Beispiel #1
0
    void FixedUpdate()
    {
        myFood = GameObject.Find("Player").GetComponent <Pickupper2>();

        if (myFood.IsHoldingObject())
        {
            foodLoc = myFood.grabPoint;

            if (Input.GetButtonDown("Eat"))
            {
                foreach (Transform child in foodLoc)
                {
                    Eatable eatable = child.GetComponent <Eatable>();
                    if (child.gameObject != null && eatable != null)
                    {
                        //If the variables are public, we can do this:

                        //myFood.isHolding = false;
                        //myFood.buttonDown = false;
                        //myFood.pickup = null;

                        // if No, I've created a function inside of Pickupper2 Script

                        Vector3 foodSize = child.gameObject.transform.localScale;
                        StartCoroutine(EatTheShit(child, foodSize, duration));
                    }
                }
            }
        }
    }
Beispiel #2
0
    public void EatFood()
    {
        myFood = GetComponentInParent <Pickupper2>();

        if (myFood.IsHoldingObject())
        {
            foodLoc = myFood.grabPoint;
            foreach (Transform child in foodLoc)
            {
                Eatable eatable = child.GetComponent <Eatable>();
                if (child.gameObject != null && eatable != null)
                {
                    Vector3 foodSize = child.gameObject.transform.localScale;
                    StartCoroutine(EatTheShit(child, foodSize, duration));

                    if (eatable.name == "apple(Clone)")
                    {
                        foodEaten += 10;
                    }
                    else if (eatable.name == "chicken(Clone)")
                    {
                        foodEaten += 100;
                    }
                    else if (eatable.name == "water")
                    {
                        foodEaten += 2;
                    }
                }
            }
        }
    }
Beispiel #3
0
    //player actions
    private void PlayerActions()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        RigidBodyController controller = GetComponentInParent <RigidBodyController>();

        controller.Locomote(new Vector3(horizontal, 0, vertical));
        controller.Rotate();


        if (Input.GetKeyDown(KeyCode.Space))
        {
            controller.Jump();
        }

        if (Input.GetMouseButtonDown(0))
        {
            //become other player on left click
            CreateRay();
        }
        if (Input.GetKeyDown(KeyCode.C))
        {
            if (CamMode == 1)
            {
                CamMode = 0;
            }
            else
            {
                CamMode++;
            }
            StartCoroutine(CamChange());
        }
        if (Input.GetKeyDown(KeyCode.U))
        {
            if (actionPickup && actionPickup.IsHoldingObject())
            {
                Usable usable = actionPickup.HeldObject().GetComponent <Usable>();
                if (usable)
                {
                    usable.Use();
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.I))
        {
            //call spawn function
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            //call pickup function
            actionPickup = GetComponentInParent <Pickupper2>();
            actionPickup.PickUp();
        }
        if (Input.GetKeyDown(KeyCode.E))
        {
            //call eat function
            actionEat = GetComponentInParent <Eat>();
            actionEat.EatFood();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            if (actionPickup && actionThrow && actionPickup.IsHoldingObject())
            {
                actionThrow.ThrowObject();
            }
        }
        //... more actions
    }