- Home /
Enemy AI scripting error
I made a script for an enemy AI, I don't know if I did any of this right really. I keep getting the error: Assets/EnemyAI.cs(11,13): error CS1519: Unexpected symbol `Awake' in class, struct, or interface member declaration
My script:
using UnityEngine; using System.Collections;
public class EnemyAI : MonoBehaviour { public Transform target; public int moveSpeed; public int rotationSpeed;
private Transform myTransform
void Awake() {
myTransform = transform;
}
// Use this for initialization
void Start () {
GameObject go = GameObject.FindGameObjectWithTag("Player");
target = go.transform;
}
// Update is called once per frame
void Update () {
}
}
Can someone please tell me what I have wrong? Thanks!
Fixed the script, but now the enemy does not move. Help?
Answer by brandon1 · Mar 23, 2011 at 04:06 PM
It's a parsing error, anytime you get an unexpected symbol in a programming language and you know it's part of the language, like Awake. Look up one line for a bug. You forgot the semicolon after myTransform.
On the question of is this code is right, it depends what you are trying to do. Right now you are copying the references for your transforms around in a few places, not sure what you're trying to do with those.
Answer by james flowerdew · Mar 23, 2011 at 04:08 PM
A workaround:
in your goodyscript define a "public static goodyscript gThis;", and in start of goodyscript set "gThis =this;"
then look foor "goodyscript.gThis.transform.position" instead
better than doing a "find" on every frame anyway.
and could be used elsewhere at a guess