- Home /
Define var target : Transform; within the script
I'm trying to predefine the var target : Transform; object within the script for use on a instantiated prefab.
var target : Transform; var damping = 6.0; var smooth = true;
@script AddComponentMenu("Camera-Control/Smooth Look At")
function LateUpdate () { if (target) {
if (smooth)
{
// Look at and dampen the rotation
var rotation = Quaternion.LookRotation(target.position - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
else
{
// Just lookat
transform.LookAt(target);
}
}
}
function Start () { // Make the rigid body not change rotation if (rigidbody) rigidbody.freezeRotation = true; }
Why not set target in Start()? Best I could offer given how little explanation you've given.
Answer by Caiuse · Feb 16, 2011 at 09:51 PM
I think i explained myself wrong but anyway, I was trying to define a target using a tag, so i had to add the following to the LookAt script.
var player : GameObject;
player = GameObject.FindWithTag("Player");
transform.LookAt(player.transform);
http://forum.unity3d.com/threads/78332-Using-LookAt()-with-tags
Thanks
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Move Object Smoothly 1 Answer
LookAt not working, points in wrong direction. 1 Answer
Animation scripting. 1 Answer