r/programmingrequests • • Apr 05 '17

Can someone please help with this error I'm getting?

Sorry if this is in the wrong place, I'm building a game with my friends and I just want to show them a couple of ideas, one being point and click, and I have the ground and objects set up and have done the Navmesh for them, but i'm trying to fix the player moving to where I click.

only where I have added the ** ** I'm getting this error:

C# conditional operator error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement

Thanks

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.AI;

public class Worldinteraction : MonoBehaviour { UnityEngine.AI.NavMeshAgent playerAgent;

void start()
{
	**playerAgent - GetComponent<NavMeshAgent> ();**
}

// Use this for initialization


// 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;	
		}
	}
}

}

2 Upvotes

2 comments sorted by

2

u/NoG5 Apr 06 '17

looks like you trying to set playerAgent to the return of GetComponent with a - at first glance

1

u/coulsdoneagle Apr 06 '17

Thanks I was being an idiot I have been looking at it for so long I couldn't see the - instead of =