Quantcast
Viewing all articles
Browse latest Browse all 1488

All enemies die when one does

I'm having a problem with the scripting in my game. When I jump on one enemy to kill it all the enemies die. They were all dragged into the scene view from a prefab. Here is the script on my enemies: public float velocity = -3; public Transform startCast; public Transform endCast; public bool GroundHit; public bool OnGround; public bool WallHit; public Transform WallCheckStart; public Transform WallCheckEnd; public Transform GroundCheckStart; public Transform GroundCheckEnd; public LayerMask GroundLayer; public LayerMask WallLayer; public static bool dead, noMoreKillPlayer; private GameObject me; public BoxCollider2D Box1, Box2; Rigidbody2D rg; SpriteRenderer spritey; IEnumerator KillSequence(){ if (PlayerControls.DoneKilling) { rg.gravityScale = 0; spritey.sortingLayerName = "EnemyBG"; Box1.enabled = false; Box2.enabled = false; yield return new WaitForSeconds (2f); Destroy (me); } } void Start () { me = this.gameObject; dead = false; rg = GetComponent (); spritey = GetComponent (); } void FixedUpdate () { rigidbody2D.velocity = new Vector2 (velocity, rigidbody2D.velocity.y); GroundHit = Physics2D.Linecast (startCast.position, endCast.position, GroundLayer); OnGround = Physics2D.Linecast (GroundCheckStart.position, GroundCheckEnd.position, GroundLayer); WallHit = Physics2D.Linecast (WallCheckStart.position, WallCheckEnd.position, WallLayer); if (!GroundHit && OnGround || WallHit) { transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y); velocity *= -1; } if (dead) { this.velocity = 0; StartCoroutine(this.KillSequence()); } } This script is on the killbox which is a child of the enemy: public GameObject me; void OnTriggerEnter2D(Collider2D hit){ if (hit.tag == "Feet") { SimpleEnemy.dead = true; SimpleEnemy.noMoreKillPlayer = true; } } void FixedUpdate(){ if (SimpleEnemy.dead == true && PlayerControls.DoneKilling == true) { me.SetActive(false); } } I think the problem is that the dead variable is being set true for everyone with the enemy script on which is all of the enemies. Would I have to distinguish which enemy I am jumping on in either the player or enemy script? If so, how would I do that?

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>