Backround loader

Hi, I wrote a JavaScript where if the player gets a certain from an object, that object changes into something else (a lowpoly version or even an empty object). I use use triggers, and If the player enters the trigger it changes to a high poly version, and vice versa.

You need both the highpoly.js

//To use: attach this code to your an empty object, and make your high poly prefab a child of your game object. Next, add a box collider to your game object and make the collider a trigger(make sure that it is consideribly larger than your high-poly prefab). Do the same with your low-poly object, use lowpoly.js instread. Give both empty game objects names, and assign eachother as "object" in the editor (make sure both are prefabs). To use, add your lowpoly containing prefab to the scene and enjoy (lowpoly will be changed to high poly if you are within the specified range). If you use, be sure to give credit to Given Borthwick


var object : Transform;


function OnTriggerExit(  otherObject3: Collider        ){

if(otherObject3.gameObject.tag == "Player"){
	Destroy(gameObject);

if (object)
		Instantiate (object, transform.position, transform.rotation);

}
}

and lowpoly.js

//instructions on other script

var object : Transform;


function OnTriggerEnter(  otherObject3: Collider        ){

if(otherObject3.gameObject.tag == "Player"){
	Destroy(gameObject);

if (object)
		Instantiate (object, transform.position, transform.rotation);
}
}

Webplayer:
http://dl.dropbox.com/u/11957743/Test.html
Unity package:
http://www.filefront.com/17855654/Highpoly-lowpoly.unitypackage

Bump

You’re doing this in Start(), which only gets called once.

Background is spelled background, not backround.

“wrote a java script” means that you wrote a script in Java. I know it sounds redundant to say, “I wrote a JavaScript script,” but that would be the way to say it if you wanted to say it the way you said it. :wink: You can use different phrasing if you don’t like the look/sound of it.

The link in your signature does not work, as a clickable link.

Thanks. I changed Start() but still no luck.

You put your distance checking in Update() on both? You’ll also need a switch so it doesn’t call inSight or outofSight every frame.

Still no luck

Can you post the code with the changes you made?

Code updated. Still not working. Ive rewrote it abou 5 time now, and can’t figure out whats wrong with it– I am of course still a novice at scripting.

Hence, why posting the code will allow us to help you…

Like I said, the new code is posted in place of the old.

Oh sorry I misunderstood “Code updated.” I didn’t know you meant in the post, I thought you meant in your project only (my mistake). So, if it is not working, what is it doing exactly?

And faster =]

Thanks to sccrstud92, elveatles, and Jessy for trying to help. Thankfully, I figured out a new way to do it, but your advice was appreciated nonetheless.

The scrips are free for anyone to use.