Example #1
0
    void Update()
    {
        Debug.Log(currentPatrolPoint);

        //Actual distance between player and enemy.
        float distance = Vector3.Distance(transform.position, player.transform.position);


        if (distance < enemyDistanceDetect) // If the player is too close to the enemy...
        {
            // If player has picked up object, enemy will run away from player
            if (pickUpFunction.IsHoldingObject()) // We are calling the IsHoldingObject() function from the Pickupper script which returns a boolean called isHolding.
            {
                Vector3 dirToPlayer = transform.position - player.transform.position;
                Vector3 newPos      = transform.position + dirToPlayer;
                controller.NavMeshProvider(newPos);
            }
            else   // If player hasn't picked up object, enemy will run towards player and chase him
            {
                controller.NavMeshProvider(player.transform.position);
            }
        }
        else   // If the player is too far from enemy, he patrols
        {
            // When enemy has reached one patrol point, go to the next one
            if (!agent.pathPending && agent.remainingDistance < 0.5f)
            {
                GoToNextPoint();
            }
        }
    }
Example #2
0
    public void DropHeldObject()
    {
        if (pickupper.IsHoldingObject())
        {
            //set the child gameobject
            heldObject = grabPoint.gameObject.transform.GetChild(0).gameObject;
            //gettting the component
            changeTag = grabPoint.GetComponentInChildren <ChangeTag>();
            //changing the tag when thrown
            changeTag.ChangeTheTag();

            //fix the gravity an
            heldObject.GetComponent <Rigidbody>().useGravity  = true;
            heldObject.GetComponent <Rigidbody>().isKinematic = false;
            heldObject.GetComponent <BoxCollider>().isTrigger = false;

            //detach the child
            grabPoint.transform.DetachChildren();

            //add force
            heldObject.GetComponent <Rigidbody>().AddForce(grabPoint.gameObject.transform.forward * 300);
        }
        else
        {
            Debug.Log("Not holding it");
        }
    }
Example #3
0
 //Call this for player throw. This will throw the object where the player is facing.
 public void ThrowObject()
 {
     if (pickupper.IsHoldingObject())
     {
         heldObject = pickupper.HeldObject();
         var throwRb = heldObject.GetComponent <Rigidbody>();
         pickupper.ButtonCheck();
         var vel = Projectile.GetProjectileVelocity(maxForce, throwDistance, transform.up, transform.forward);
         throwRb.AddForce(vel, ForceMode.VelocityChange);
         throwSound.Play();
         heldObject = null;
     }
     else
     {
         heldObject = null;
     }
 }
Example #4
0
 // Update is called once per frame
 void Update()
 {
     //use button is E
     if (Input.GetButtonDown("Use"))
     {
         if (PickUp.IsHoldingObject())
         {
             Usable usable = PickUp.HeldObject().GetComponent <Usable>();
             if (usable != null)
             {
                 usable.Use();
                 Debug.Log("use Pressed");
             }
         }
     }
 }
Example #5
0
    public void EatFood()
    {
        myFood = GetComponentInParent <Pickupper>();

        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));
                }
            }
        }
    }
Example #6
0
//    void Update() {
//        print("isChanging " + isChanging);
//        print("isSmall " + small);
//    }

    public void EatFood()

    {
        if (myFood.IsHoldingObject())
        {
            foodLoc = myFood.grabPoint;
            foreach (Transform child in foodLoc)
            {
                Eatable eatable = child.GetComponent <Eatable>();
                foodSize = child.gameObject.transform.localScale;
                if (child.gameObject != null && eatable != null)
                {
                    if (!small && !isChanging)
                    {
                        StartCoroutine(EatTheObj(child, foodSize, playerSize, duration));
                    }
                }
            }
        }
    }
    //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))
        {
            //checks for the actionpickup script and if it is holding an object
            if (actionPickup && actionPickup.IsHoldingObject())
            {
                //get the spawner script in the children component of pickupper script
                actionSpawn = actionPickup.GetComponentInChildren <Spawner>();
                //call spawn function
                actionSpawn.Spawn();
            }
        }
        if (Input.GetKeyDown(KeyCode.P))
        {
            //call pickup function
            actionPickup = GetComponentInParent <Pickupper>();
            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
    }