예제 #1
0
    private void Update()
    {
        /*
         * Basic movement
         */

        //Do not move if game is finished or you are stunned
        if (!this.GetGameManager().GetComponent <Level>().GameRunning || Stunned)
        {
            return;
        }

        //Get movement axis
        Vector2 axis = new Vector2(
            x: Input.GetAxis(HorizontalAxis),
            y: Input.GetAxis(VerticalAxis)
            );

        //Store direction of the player
        if (axis != Vector2.zero)
        {
            Direction = DirectionExtensions.Construct(axis.x, axis.y);
        }


        //Apply movement to player
        if (GetComponentInChildren <Grabber>().IsGrabbing)
        {
            Move(axis, MoveSpeed * GetComponentInChildren <Grabber>().GrabbedItems.Average(i => i.GetComponent <Junk>().SpeedMultipler));
        }
        else
        {
            Move(axis, MoveSpeed);
        }


        //Rotate the player
        transform.SetEuler2D(CommonExtensions.RealAngleBetween(transform.Position2D(), transform.Position2D() + Direction.ToVector2()));
    }