hello, I was hoping one of you could write me a small script for JavaScript that will cause a invisible object to appear when stepping in a trigger and then disappear a few seconds later.
-
#pragma strict
2…
- function OnTrigger
-
meshRenderer.enabled = false
is the only script i can think of and im pretty sure that wont work
Object 1: whatever.js
function OnTriggerEnter ( )
{
vat objactivate : GameObject = GameObject.Find(“Object2”); // Find Object2
objactivate.active = true ; // Make it appear
var disScript : DisappearScript = GameObject.Find(“Object2”).GetComponent ( DisappearScript ) ; // Get Disappear Script
disScript.CounterActive = true ; // Set Disappear Script.active = true
}
object 2: DisappearScript.js
static var CounterActive : boolean = false ; // Active ?
var counterTime : float = 10 ; // 10 seconds
function Update ( ){
if ( CounterActive ){// If active
if ( Mathf.Ceil ( counterTime ) > 0 )// If time hasn't run out
{
counterTime -= 1 * Time.deltaTime ; // Minus a second
}else{// If time run out
gameObject.active = false ; // Disappear
}
}else{ counterTime = 10 ; } // Reset if not active
}