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);
}
}
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. 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.
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?
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.