I am working on a 3D first person shooter project and have written a script following carefully line by line a tutorial on YouTube. The script is intended to perform a recon / wander on a character. Despite having followed the tutorial, the script gives me 4 errors which I am unable to correct.
These are the errors:
Assets/wander.cs(40,78): error CS1525: Unexpected symbol hit' Assets/wander.cs(44,22): error CS1519: Unexpected symbol
return’ in class, struct, or interface member declaration
Assets/wander.cs(44,37): error CS1519: Unexpected symbol `;’ in class, struct, or interface member declaration
Assets/wander.cs(46,1): error CS8025: Parsing error
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Rigidbody))]
[RequireComponent(typeof(NavMeshAgent))]
public class wander : MonoBehaviour {
public NavMeshAgent agent;
[Range(0, 100)] public float speed = 0.5f;
[Range(1, 500)] public float walkRadius = 50f;
// Use this for initialization
public void Start ()
{
agent = GetComponent<NavMeshAgent>();
if (agent != null)
{
agent.speed = speed;
agent.SetDestination(RandomNavMeshLocation());
}
}
// Update is called once per frame
public void Update()
{
if (agent != null && agent.remainingDistance <= agent.stoppingDistance)
{
agent.SetDestination(RandomNavMeshLocation());
}
}
public Vector3 RandomNavMeshLocation()
{
Vector3 finalPosition = Vector3.zero;
Vector3 randomDirection = Random.insideUnitSphere * walkRadius;
randomDirection += transform.position;
if (NavMesh.SamplePosition(randomDirection, out NavMeshHit hit , walkRadius, 1))
{
finalPosition = hit.position;
}
return finalPosition;
}
}