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);

1 Answer

1

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.

–

Ah, okay, I get your point. Thanks

–