- Home /
Convert a GameObject to a transform?
What i need to do is find a GameObject with findtag; in the scene and convert it to a transform so i can use
`transform.LookAt(target);`
If there is another way of doing this that would also be great! Thanks Guys! I cant seem to wrap my head around it yet.
#pragma strict
//If you want to change tag in inspector. $$anonymous$$ainCamera is default just for this example.
var targetTag : String = "$$anonymous$$ainCamera";
private var target : Transform;
function Start()
{
//Use GameObject.FindWithTag as usual, then reference the GameObject's Transform component.
target = GameObject.FindWithTag(targetTag).transform;
print(target.name);
}
Answer by The Kracken · Dec 02, 2013 at 09:35 PM
If the target in your code is the GameObject just use this: transform.LookAt(target.transform);
omg... so simple. haha i hate that. Thanks $$anonymous$$an. I was about to falcon punch my computer.
Your answer
Follow this Question
Related Questions
Find Gameobject Transform, dont work now? 3 Answers
GameObjectWithTag Child 1 Answer
GameObject.Find("something")..how to use with transform,audiosource and texture ? 1 Answer
All the objects in my script choose the same target. 2 Answers
Finding class where current GameObject is assigned to as a var 1 Answer