I have been following this tutorial: shorturl.at/bvxz4
In the WorldInteraction script he his teaching us to right. I have this line of code public class WorldInteraction : MonoBehaviour
the “MonoBehaviour” however is not lit up and whenever I try to put this script into the player I get an error saying “Can’t add script behaviour AssemblyInfo, The script needs to derive from MonoBehaviour”. Any help with this would be appreciated!
FULL CODE:
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>();
}
// 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;
}
}
}