// Update is called once per frame void FixedUpdate() { Debug.Log("Update firing"); Debug.Log(objects.Count); DesiredAction = Action; //finds the closest object of the target type if (objects.Count > 0) { Debug.Log("Polling objects"); Vector3 currentPosition = this.transform.position; float nearestDist = Mathf.Infinity; foreach (GameObject obj in objects) { Vector3 dist = obj.transform.position - currentPosition; float distSqr = dist.sqrMagnitude; if (distSqr < nearestDist) { nearestDist = distSqr; WhatToTarget = obj; Debug.Log("Target has fired"); } } Debug.Log("loop broken"); Debug.Log(WhatToTarget.transform.position); inRange = true; //here is where i call the navmesh script using obj.transform as the destination //hopefully the navmesh script gets called properly, and accepts the .position NewDirection = (WhatToTarget.transform.position); Navigate.NavMeshProvider(NewDirection); //Navigate.NavMeshProvider(WhatToTarget.transform.position); Debug.Log("Navmesh has fired"); if (this.action_distance > Vector3.Distance(this.transform.position, NewDirection)) { Debug.Log("arrived"); ActionPickup.PickUp(); } //There needs to be a check for when the navmesh has finished before calling the desired action script /* * //otherGameObject.GetComponent("OtherScript").DoSomething(); * //Conditional arguements for different actions, must fit the different call limitations of the action scripts * if(DesiredAction == Pickupper2){ * //issue: calling pickup requires a button to be pressed, and does not specify what to pick up in the function * ActionPickup.PickUp(); * } * if(DesiredAction == Usable){ * //as per documentation, this should use the targeted object and not destroy it afterwards * ActionUse.Use(WhatToTarget, false); * } * * if(DesiredAction == Break){ * //this should destroy the target object. Presupposes that the object being targetted with the purpose of breaking has the script attached * //ideally should simply call the break function on the targeted object * //ActionBreak.WhatToTarget.explode(); * WhatToTarget.GetComponent<"Break">.explode(); * } * * if(DesiredAction == Combust){ * //should burn the targeted object: may need to specify the gameObject WhatToTarget * //ActionCombust.Burn(); * WhatToTarget.GetComponent<"Combust">.Burn(); * } * if(DesiredAction == Eat){ * //should eat the targeted WhatToTarget * ActionEat.Eat(); * } */ } }
//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 }