// Update is called once per frame void Update() { Vector3 target = (nextNode.transform.position + nextNode.spawnOffset) - transform.position; if (!target.Equals(Vector3.zero) && energy > 0) { transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.LookRotation(target, Vector3.up), 5 * energy); } //move to the next node when we reach our target if (target.sqrMagnitude < nodeRange) { //reached the end of the path if (nextNode.nextNodes.Count <= 0) { manager.health -= (int)maxHealth; GameObject.Destroy(gameObject); } else { nextNode = nextNode.getNextNode(); target = (nextNode.transform.position + nextNode.spawnOffset) - transform.position; } } velocity = target.normalized * speed * Time.deltaTime; transform.position += velocity * energy; //update status effects energy = 1; for (int i = 0; i < effects.Count; i++) { effects[i] += Vector3.forward * Time.deltaTime; if (effects[i].z >= effects[i].y) { effects.RemoveAt(i); i--; } else { energy *= effects[i].x; } } float ratio = health / maxHealth; renderer.material.color = new Color(.9f, Mathf.Lerp(.25f, .05f, ratio), 0, energy); }