- Home /
Question by
tracerstevens · Mar 30, 2012 at 06:01 AM ·
cameracontrol
Control camera target from another scripts
Hey guys, I've been looking at other scripts and I swear this should work but it doesn't:
var target_ball : Rigidbody;
static var game_state : int = 2;
function Awake()
{
DontDestroyOnLoad (transform.gameObject);
}
function OnGUI()
{
switch(game_state)
{
case 2: // SET THROW
if(!gameObject.Find("Ball"))
{
var target = Instantiate(target_ball, Vector3(10, 5.2, 3.75), Quaternion.identity);
target.name = "Ball";
GameObject.Find("Main Camera").GetComponent("SmoothLookAt").target = target;
}
}
}
The camera has SmoothLookAt.js with var target : Transform;
The error reads: BCE0019: 'target' is not a member of 'UnityEngine.Component'.
How do I change the target of the camera from this script?
Comment
Best Answer
Answer by $$anonymous$$ · Mar 30, 2012 at 12:27 PM
Use
var lookAtScript: SmoothLookAt = GameObject.Find("Main Camera").GetComponent("SmoothLookAt");
lookAtScript.target = target;
insead of
GameObject.Find("Main Camera").GetComponent("SmoothLookAt").target = target;
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Mouse orbit + Smooth follow script question 0 Answers
2.5d camera control script 1 Answer
Attaching an RTS scrolling script to a camera (Noob Question) 3 Answers
Shaking camera 0 Answers