void Chase() { if (target == null) { fsm.popState(); return; } if (toTarget.sqrMagnitude > forgetDistance * forgetDistance) { target = null; } else if (toTarget.sqrMagnitude > shootDistance * shootDistance) { toTarget.Normalize(); movement.Move(toTarget, true); shootingScript.Aim(toTarget); } else { fsm.pushState(Shoot); } }
// Update is called once per frame void Update() { Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized; //input = (input + lastInput) / 2; movement.Move(input, Input.GetKey(KeyCode.LeftShift)); lastInput = input; if (input.y == 0) { if (input.x > 0) { shootingScript.Aim(Vector2.right); } if (input.x < 0) { shootingScript.Aim(Vector2.left); } } if (input.x == 0) { if (input.y > 0) { shootingScript.Aim(Vector2.up); } if (input.y < 0) { shootingScript.Aim(Vector2.down); } } if (Input.GetMouseButton(0)) { shootingScript.Shoot(); } }
// Update is called once per frame void Update() { if (target == null) { return; } Vector2 toTarget = target.position - transform.position; if (toTarget.sqrMagnitude > forgetDistance * forgetDistance) { target = null; } else if (toTarget.sqrMagnitude > 1) { toTarget.Normalize(); shootingScript.Aim(toTarget); shootingScript.Shoot(); } }
// Update is called once per frame void Update() { Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized; input = (input + lastInput) / 2; //Debug.Log(input); movement.Move(input, Input.GetKey(KeyCode.LeftShift)); lastInput = input; Vector2 aim = Camera.main.ScreenToWorldPoint(Input.mousePosition) - shootingScript.aimTransform.position; aim.Normalize(); shootingScript.Aim(aim); if (Input.GetMouseButton(0) && shoot) { shootingScript.Shoot(); } }