void Update() { if (target == null && fuel > 0) { target = player; } if (onMyWay && target != null) { commonProc.trackToObject(body, target, 7f, false); } if (Time.time > nextActionTime) { nextActionTime += 1; fuel -= 1; //Missile, no more fuel if (fuel < 0) { target = null; body.angularVelocity = transform.right.x * 30f; body.gravityScale = 0.5f; Destroy(gameObject, 4); //anim.SetTrigger("StopTrigger"); not working } } if (Assistant.lookForChaff) { if (target == player || target == null) { GameObject[] chaff = GameObject.FindGameObjectsWithTag("Chaff"); foreach (GameObject go in chaff) { target = go; break; } } } if (globals.cylinder != null && (target == player || target == null)) { Cylinder script = globals.cylinder.GetComponent <Cylinder>(); if (script.attached) { target = globals.cylinder; } } }
void Update() { if (asteroid == null && !hadTarget) { asteroid = commonProc.findClosestGameObject(this.gameObject, "Enemy"); hadTarget = true; } if (asteroid != null && !attached) { attached = commonProc.trackToObject(body, asteroid, 10f, true); } else if (asteroid != null && attached) { Rigidbody2D aBody = asteroid.GetComponent <Rigidbody2D>(); body.angularVelocity = aBody.angularVelocity; body.velocity = aBody.velocity; } else if (hadTarget) { Destroy(this.gameObject); } }