- Home /
Help with a simple following AI
So I have been working on a basic javascript code that makes an object, in my case a zombie, look at and follow another object, the Player. For some reason this code is pulling the error: "'transform' is not a member of 'Object'. "
Any ideas? Here is my code:
pragma strict
var speed = .7;
var target;
function Start () {
target = GameObject.Find("Player");
}
function Update () {
transform.LookAt(target.transform);
transform.position += transform.forward * speed * Time.deltaTime;
}
try using GameObject ins$$anonymous$$d on var in the type definition of target and see if something changes
Answer by geroppo · Jan 16, 2014 at 10:44 PM
replace "var target" with "var target : GameObject"
also i wouldn't recommend using GameObject.Find, because it's kind of slow if you have alot of objects in the scene, better use GameObject.FindWithTag , then create and assing the tag Player to the object
Your answer
Follow this Question
Related Questions
UCE0001 and BCE0044 Errors 1 Answer
Error on Line 28: expecting EOF found "}" 2 Answers