- Home /
GameObject.FindWithTag("Player") not working.
#pragma strict
var player : GameObject;
function Start () {
player = GameObject.FindWithTag("Player");
}
function Update () {
if (!Physics.Linecast (transform.position, player.position)) {
Debug.DrawLine (transform.position, player.position, Color.green);
Debug.Log ("Player in sight!");
}
else{
Debug.DrawLine (transform.position, player.transform.position, Color.red);
Debug.Log ("NO Player in sight!");
}
}
Why does this not work? It says (10,51): BCE0019: 'position' is not a member of 'UnityEngine.GameObject'.
How can i fix this?
Come on...where is the error? What is the type of player? What are you accessing and mostly how are you doing the same three lines later?
The error is that the scene wont load because of the error that i mentioned in my original post. The player is just a Object tagged as "Player". Not sure what you mean by "What are you accessing.."
Can you please open the question again since i still don't have an answer. Otherwise i have to make a new one...
Answer by fafase · Jul 20, 2014 at 08:17 PM
Player is of type GameObject.
Debug.DrawLine (transform.position, player.position, Color.green);
here you are trying to access player.position and this is the error.
two lines later:
Debug.DrawLine (transform.position, player.transform.position, Color.red);
you use player.transform.position and magically no error.
Conclusion?
Thank you. I already found that out. I guess you were right to close the question after all. Sorry but sometimes i miss the most obvious things.
Your answer
Follow this Question
Related Questions
Get Object at a position 2 Answers
Finding the position of an object 1 Answer
Get position for each Gameobject (in array) ? 0 Answers
GameObject change Position after game started 1 Answer
All the objects in my script choose the same target. 2 Answers