What needs to be changed in the coding for it to work again from a tutorial from Aaron Hibberd?
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Monster : MonoBehaviour {
public GameObject player;
public AudioClip[] footsounds;
private UnityEngine.AI.NavMeshAgent nav;
private AudioSource sound;
private Animator anim;
private string state = "idle";
private bool alive = true
// Use this for initialization
void Start() {
nav = GetComponent<UnityEngine.AI.NavMeshAgent> ();
sound = getcomponent<AudioSource> ();
anim = getcomponent<Animator> ();
nav.speed = 1.2f;
anim.speed = 1.2f;
}
public void footstep( int _num)
{
sound.clip = footsounds [_num];
sound.Play ();
}
// Update is called once per frame
void Update () {
if{alive){
anim.SetFloat ("velocity", nav.velocity.magnitude);
nav.SetDestination (player.transform.position);
//Idle//
if(state == "idle")
{
//pick a random place to walk//
vector3 randomPos = Random.insideUnitSphere*20f;
NavMeshHit navHit;
navMesh.SamplePosition(transform.position + ranDomPos, out navHit,20f,NavMesh.AllAreas);
nav.SetDestination(navHit.Position);
state = "walk";
}
//walk//
if(state == "walk")
{
if(nav.remainingDistance <= nav.stoppingDistance && !nav.pathPending)
{
state = "idle";
}
}
}
}
}
Nothing is broken. I was co$$anonymous$$g back to work on it and it came up with 8 errors on the script when I was testing it. Just wondering if it is the program messing with the code structure or something has changed through an update.
You have around 4-5 typo, Unity (well c#) is case sensitive.
getcomponent should be : GetComponent ranDomPos should be : randomPos nav$$anonymous$$esh.SamplePosition.... should be Nav$$anonymous$$esh.SamplePosition .... nav.SetDestination(navHit.Position); should be nav.SetDestination(navHit.position);
private bool alive = true missing ";" at end of the line : private bool alive = true;
if{alive){ should be if(alive){
Thanks for the help. That cleared out 4 out of the eight. It is still having issues with void start. Im not sure why since the script came with that.
using UnityEngine;
public class $$anonymous$$onster : $$anonymous$$onoBehaviour
{
public GameObject player;
public AudioClip[] footsounds;
private Nav$$anonymous$$eshAgent nav;
private AudioSource sound;
private Animator anim;
private string state = "idle";
private bool alive = true;
private void Start()
{
this.nav = this.GetComponent<Nav$$anonymous$$eshAgent>();
this.sound = this.GetComponent<AudioSource>();
this.anim = this.GetComponent<Animator>();
this.nav.speed = 1.2f;
this.anim.speed = 1.2f;
}
public void footstep(int num)
{
this.sound.clip = this.footsounds[num];
this.sound.Play();
}
private void Update()
{
if (this.alive)
{
this.anim.SetFloat("velocity", this.nav.velocity.magnitude);
this.nav.SetDestination(this.player.transform.position);
// Idle//
if (this.state == "idle")
{
// pick a random place to walk//
var randomPos = Random.insideUnitSphere * 20f;
Nav$$anonymous$$eshHit navHit;
Nav$$anonymous$$esh.SamplePosition(this.transform.position + randomPos, out navHit, 20f, Nav$$anonymous$$esh.AllAreas);
this.nav.SetDestination(navHit.position);
this.state = "walk";
}
// walk//
if (this.state == "walk")
{
if ((this.nav.remainingDistance <= this.nav.stoppingDistance) && !this.nav.pathPending)
{
this.state = "idle";
}
}
}
}
}
Your answer
Follow this Question
Related Questions
Assets/Scripts/GenerateLandscape.cs(41,60): error CS1525: Unexpected symbol `true' 1 Answer
Why do I have errors on all of my private declarations and on my void update? 1 Answer
Unexpected symbol error 0 Answers
Can someone Help Me Unexpected Symbol '(' in class, struct ,or interface 2 Answers
Unexpected symbol `object' in class, struct, or interface member declaration. 1 Answer