private void Update() { if (state == CharacterState.death) { agent.Stop(); movement.AnimateDeath(); return; } if (state == CharacterState.bomb) { FindShortestTarget(); agent.SetDestination(target.position); } else if (currBomber) { RaycastHit2D[] hits; Vector3 dir = Vector3.zero; // Vector3 dest = this.transform.position + dir.normalized; Vector3 dest = this.transform.position; float randValue = Random.value; if (randValue < 0.6f) { dir = (this.transform.position - currBomber.transform.position); } else { dir.x += -currBomber.transform.position.x; dir.y += -currBomber.transform.position.y; } foreach (string tag in targetTags) { foreach (GameObject obj in GameObject.FindGameObjectsWithTag(tag)) { if (obj.transform.position != currBomber.transform.position) { float dist = Vector3.Distance(this.transform.position, obj.transform.position); float distToBomb = Vector3.Distance(currBomber.transform.position, obj.transform.position); if (dist < 5 && dist < distToBomb) { dir += (transform.position - obj.transform.position); } } } } dest = dir; Debug.DrawLine(transform.position, dest, Color.blue, 2.5f); Debug.DrawLine(transform.position, currBomber.transform.position, Color.red, 2.5f); agent.SetDestination(dest); } movement.AnimateMove(agent.velocity, state); bombBehavior.Run(-Time.deltaTime, ref state); }
// Update is called once per frame void Update() { if (state == CharacterState.death) { movement.AnimateDeath(true); return; } // Get Input and Move Player float inputX = Input.GetAxis("Horizontal"); float inputY = Input.GetAxis("Vertical"); movement.MoveToPoint(inputX, inputY, speed, state); bombBehavior.Run(-Time.deltaTime, ref state); }
public void UpdateTimer(float time) { bombBehavior.Run(time, ref state); }