- Home /
Can you find the error in this?
public class WorldInteraction : MonoBehaviour {
// Use this for initialization
UnityEngine.AI.NavMeshAgent PlayerAgent;
void Start () {
PlayerAgent = GetComponent<UnityEngine.AI.NavMeshAgent> ();
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject ())
GetInteraction ();
}
void GetInteraction()
{
Ray interactionRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit interactionInfo;
if (Physics.Raycast (interactionRay, out interactionInfo, Mathf.Infinity)) {
GameObject interactedObject = interactionInfo.collider.gameObject;
if (interactedObject.tag == "Interactable Object") {
Debug.Log ("Interactable interacted.");
} else {
PlayerAgent.destination = interactionInfo.point;
}
}
}
}
What do you mean by "the error"? Do you get a compiler error? Or does this compile but not do what you want it to? Please provide a little information on what the problem is, how should anyone help you otherwise?
There's no need to guess - the compiler will tell you if there's a compile-time error, and Unity engine will tell you if there's a runtime error.
$$anonymous$$aybe you are new to unity/forum. You should elaborate(what are you trying to do, and what exact error are you getting in the console etc.) what's exactly happening or no one here will be able(or have the desire) to help you.
Your answer
Follow this Question
Related Questions
performance impact of destination update (navmeshagent) 0 Answers
Changing a NavMesh Destination 1 Answer
iTween-Error :: "Cannot cast from source type to destination type" 2 Answers
how can I set the destination of the nav mesh for multiple objects 2 Answers
SOLVED - How to access variable from another script for Instantiate prefab 2 Answers