Water splash issues...

Hi guys,

Because the default water prefabs don’t have any scripts for splashes, I had to write this script:

`
#pragma strict

var splashPrefab : GameObject;

function OnTriggerEnter (other : Collider) 
{
    Instantiate(splashPrefab, other.attachedRigidbody.position, Quaternion.identity);
}
`

This script was then attached to Water4Example (Advanced), and splashPrefab was set to Water Surface Splash (both prefabs are part of the standard assets). When something collides with my water, the splash appears and goes on forever. How do I time-limit it?

MachCUBED

You can create a counter a couple of different ways. You can use a while loop or save the Time.time when the trigger happens and add count time to that, then have a conditional that destroys the object when the time is reached. While loop is better

#pragma strict

var splashPrefab : GameObject;

function OnTriggerEnter (other : Collider) 
{
    var sI=Instantiate(splashPrefab,other.attachedRigidbody.position,Quaternion.identity);
    SplashCounter(sI.gameObject,3.6);
}
function SplashCounter(splashInstance:GameObject,timer:float)
{
    t:float=0;
    while(t<1)
    {
        t+=Time.deltaTime/timer;
    }
    Destroy(splashInstance);
}

#pragma strict

var t : float = 0 ;

var splashPrefab : GameObject;

function OnTriggerEnter (other : Collider)

{

var sI=Instantiate(splashPrefab,other.attachedRigidbody.position,Quaternion.identity);

SplashCounter(sI.gameObject,3.6);

}

function SplashCounter(splashInstance:GameObject,timer:float)

{

while(t<1)

{

t+=Time.deltaTime/timer ;

}

Destroy(splashInstance) ;

}