Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (canMove == false)
        {
            return;
        }

        // Move
        rigidbody.MovePosition(rigidbody.position + (velocity * moveSpeed * Time.deltaTime));

        // Change direction
        if (velocity.x != 0)
        {
            float direction = velocity.x > 0 ? 180 : 0;
            transform.eulerAngles = new Vector3(0, direction, 0);
        }

        // Interact
        if (Input.GetKeyDown(KeyCode.Mouse0))
        {
            // NOTE:(Nathen) We prioratize pushables over interactables
            // This is so you never get in a situation where you can't pick up something
            // because an NPC trigger is blocking the pushable

            // Check if we can interact with a pushable or an interactable
            if (Pushable != null)
            {
                // If we are currently pushing this Pushable
                if (Pushable.GetState() == true)
                {
                    Pushable.Drop();
                }
                else
                {
                    Pushable.Push();
                }
            }
            else if (selectedInteractable != null)
            {
                selectedInteractable.Interact(this);
            }
        }
    }