- Home /
Question by
heaversm · Jun 08, 2012 at 08:49 PM ·
cameragameobjectitween
How do you write scripts attached to a game object that move the main camera
I have a game object that I am successfully tweening with javascript and iTween. I want to have this script create a reference to the scene's Main Camera, and tween that camera. How do I do this? Here's my code so far (which doesn't work).
var igniter : GameObject;
var camera : GameObject;
function Start () {
lighterUp();
}
function lighterUp(){
iTween.MoveTo(gameObject,{"y":-2.75,"time":3,"easeType": "easeInOutQuad","oncomplete":"lighterTurn"});
}
function lighterTurn(){
iTween.RotateTo(gameObject,{"y":0,"oncomplete":"lighterTurnIgniter"});
}
function lighterTurnIgniter(){
iTween.RotateTo(igniter,{"x":180});
iTween.MoveTo(camera,{"z":-50}); //Doesn't Work
}
Comment
Answer by Berenger · Jun 08, 2012 at 08:57 PM
camera is a property of component, probably defined like this :
public Camera camera{ get{ return GetComponent< Camera >(); } }
Unless that script is actually attached to the main camera, it will return null. Try Camera.main.