I have an error and don't know what the cause is, help?
So I have been coding a game that involves zombies, currently I am working on the animation and pathfinding. Whis is my nav mesh code that gets the error:
***// Update is called once per frame
void Update () {
nav.SetDestination (player.position);
controller.SetFloat ("speed", Mathf.Abs (nav.velocity.x) + Mathf.Abs (nav.velocity.z));
}***
And this is the error I get:
"A namespace cannot directly contain members such as fields or methods."
PLEASE HELP! D:
Comment
The specific line that gets the error is
void Update () {
Could you post the rest of this code? Unless your Update function is outside of a class definition, this code snippet probably isn't the problem.
Yes I will post it in this comment, thanks for replying!
using UnityEngine;
using System.Collections;
public class Enemycontroller : $$anonymous$$onoBehaviour {
Nav$$anonymous$$eshAgent nav;
Transform playerpos;
// Use this for initialization
void Awake () {
nav = GetComponent <Nav$$anonymous$$eshAgent> ();
playerpos = GameObject.FindGameObjectWithTag ("Player").transform;
controller = GetcomponentInParent<Animator> ();
}
}
// Update is called once per frame
void Update () {
nav.SetDestination (player.position);
controller.SetFloat ("speed", $$anonymous$$athf.Abs (nav.velocity.x) + $$anonymous$$athf.Abs (nav.velocity.z));
}
Answer by ata_2 · Feb 10, 2016 at 10:41 AM
from comment post if you count you can see update function is outside of MonoBehaviour delete one of } before update and add it to end