- Home /
move to next scene
Help!!! Im a newbie in unity and javascript.
I want my character move to next scene after it hits the given distance(fixdist).
Here's my code:
var targetObject : Transform;
function Start(){
targetObject = GameObject.Find("First Person Controller").transform;
}
function Update(){
var fixdist : float = "179.3872";
if (targetObject!= null){
var dist : float = Vector3.Distance(targetObject.position, this.transform.position);
print ("Distance to target Object: " + dist);
if (targetObject)
Application.LoadLevel(1);
Answer by FL · Feb 03, 2013 at 12:05 AM
If this script is in the startpoint, just change your last "if" to if (dist>=targetObject)
. Remeber also of Object.DontDestroyOnLoad
What do you mean by "If this script is in the startpoint"? Sorry, I'm still a newbie to unity and javascript. Thanks anyway. How can I also refer the dist to my targetObject?
You need to add this script component to a startpoint, even a empty object.
Your answer
Follow this Question
Related Questions
moving to next scene 1 Answer
Passing "best" to the other scene 0 Answers
Sigh... Need help with moving object a distance over time 1 Answer
Player should move box, Ai shouldn't 1 Answer