Example #1
0
    // Update is called once per frame
    void Update()
    {
        controller.UpdateControls();
        if (timeBeforeNextArrow > 0)
        {
            timeBeforeNextArrow -= GameplayTime.StepTime;
        }
        if (invincibilityRemaining > 0)
        {
            invincibilityRemaining -= GameplayTime.StepTime;
        }
        if (dead)
        {
            return;
        }
        var     controls  = controller.GetControls();
        Vector3 direction = new Vector3();

        if (controls.Down)
        {
            direction.y -= 1;
        }
        if (controls.Up)
        {
            direction.y += 1;
        }
        if (controls.Left)
        {
            direction.x -= 1;
        }
        if (controls.Right)
        {
            direction.x += 1;
        }
        var position = gameObject.transform.position;

        position  += direction.normalized * speed * GameplayTime.StepTime;
        position.x = Mathf.Clamp(position.x, bounds.xMin, bounds.xMax);
        position.y = Mathf.Clamp(position.y, bounds.yMin, bounds.yMax);
        gameObject.transform.position = position;
        if (direction != Vector3.zero)
        {
            rotationObject.transform.eulerAngles = (Vector3.forward * Vector3.SignedAngle(Vector3.up, direction, Vector3.forward));
        }
        if (controls.Shoot && timeBeforeNextArrow <= 0)
        {
            StartCoroutine(ShootArrow());
        }
    }
 public PlayerControls GetControls()
 {
     return(Controller.GetControls());
 }