- Home /
AI Follow Player "Tag" Help
Hi Guys! i have a Problem. I made a Script. but i get 5 Errors i know it's kinda of a Chain Error. The Script is Right **HERE**
Assets/Scripts/EnemyAI.cs(13,24): error CS1061: Type
UnityEngine.GameObject' does not contain a definition for
position' and no extension methodposition' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)Assets/Scripts/EnemyAI.cs(13,36): error CS1061: Type
UnityEngine.GameObject' does not contain a definition for
position' and no extension methodposition' of type
UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)Assets/Scripts/EnemyAI.cs(13,12): error CS1502: The best overloaded method match for
UnityEngine.Vector3.Distance(UnityEngine.Vector3, UnityEngine.Vector3)' has some invalid arguments 4. Assets/Scripts/EnemyAI.cs(13,12): error CS1503: Argument
#1' cannot convertobject' expression to type
UnityEngine.Vector3'Assets/Scripts/EnemyAI.cs(14,9): error CS0029: Cannot implicitly convert type
UnityEngine.GameObject' to
UnityEngine.Transform'
Well, looks like you need to define the position variable, for start.
Answer by GutoThomas · Apr 24, 2012 at 10:12 PM
Here you're trying do mix types GameObject and Transform:
target = go;
try:
target = go.transform;
Ah, I forget about something, sorry.
void Update (){
GameObject go = GameObject.FindGameObjectWithTag("Player");
if(Vector3.Distance(go.position,go.position)<$$anonymous$$Range)
You're trying to access the distance of the go without refer his transform. It should work if you change to:
if(Vector3.Distance(go.transform.position,go.transform.position)<$$anonymous$$Range)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
One player tag, two players, enemy attack who ever is closer? 1 Answer
How do I make it so that I can attack more than 1 enemy? 1 Answer
EnemyAI Script help 1 Answer
Argument out of range. 1 Answer