Skip to content

Commit

Permalink
fixed issue of bullets being shot all the time
Browse files Browse the repository at this point in the history
  • Loading branch information
payalnk committed Mar 12, 2023
1 parent 4a5e0c3 commit dddd958
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Assets/KillGuard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class KillGuard : MonoBehaviour
{
public GameObject bullet, fov;
public GameObject bullet, fov, blood;
public bool shotByBullet = false;
// Start is called before the first frame update
void Start()
Expand All @@ -16,6 +16,7 @@ void Start()
void Update()
{
if (shotByBullet){
GameObject bloodIns = Instantiate(blood, transform.position, Quaternion.identity);
Debug.Log("Shot by bullet");
Destroy(fov);
Destroy(gameObject);
Expand Down
21 changes: 20 additions & 1 deletion Assets/Scenes/SampleScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ GameObject:
m_Component:
- component: {fileID: 396401813}
- component: {fileID: 396401814}
- component: {fileID: 396401815}
m_Layer: 20
m_Name: gun2
m_TagString: Untagged
Expand Down Expand Up @@ -1422,6 +1423,23 @@ SpriteRenderer:
m_WasSpriteAssigned: 1
m_MaskInteraction: 0
m_SpriteSortPoint: 0
--- !u!114 &396401815
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 396401812}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a1f0d76dd3733422192b5d70fe2e4c74, type: 3}
m_Name:
m_EditorClassIdentifier:
Gun: {fileID: 396401813}
Bullet: {fileID: 4281599298627598602, guid: 0178f4643417944c18fe402e234d662b, type: 3}
BulletSpeed: 1200
ShootPoint: {fileID: 1463934861}
fireRate: 4
--- !u!1 &424252269
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -1601,7 +1619,7 @@ MonoBehaviour:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 459289067}
m_Enabled: 1
m_Enabled: 0
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: a1f0d76dd3733422192b5d70fe2e4c74, type: 3}
m_Name:
Expand Down Expand Up @@ -1991,6 +2009,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
bullet: {fileID: 4281599298627598602, guid: 0178f4643417944c18fe402e234d662b, type: 3}
fov: {fileID: 1073414886}
blood: {fileID: 4758788576945127766, guid: 21240158094624a7f96e26036aa4578b, type: 3}
shotByBullet: 0
--- !u!1001 &576934833
PrefabInstance:
Expand Down
2 changes: 1 addition & 1 deletion Assets/ShootScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void FaceMouse(){
void shoot(){
GameObject BulletIns = Instantiate(Bullet, ShootPoint.position, ShootPoint.rotation);
BulletIns.GetComponent<Rigidbody2D>().AddForce(BulletIns.transform.right * BulletSpeed);
Destroy(BulletIns, 3);
Destroy(BulletIns, 2);
}

}

0 comments on commit dddd958

Please sign in to comment.