OnTriggerEnter and transform.localScale with Time.deltaTime problem

Hi,

I feel I am close to understanding this but can’t quite nail it.

I have a OnTriggerEnter (bulletCollision:Collider) function.
Inside that function I am trying to scale a gameObject using Time.deltaTime.

What happens is that the object instantly scales but not over time.

I now know that Time-deltaTime should happen in a function Update().

However, I am having difficulty in working out how to do this.

Here is an example of code I started with:

function OnTriggerEnter (bulletCollision:Collider)
{
	//Detect Collision
	if(bulletCollision.gameObject.name == "Bullet(Clone)"){
	
	GameObject.Find("TargetCube(Clone)").transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;


	}
}

}

After researching I have moved on to turning the scale I want to do into a Function so that I could get it to work by some how calling it in a function Update():

function OnTriggerEnter (bulletCollision:Collider)
{
	//Detect Collision
	if(bulletCollision.gameObject.name == "Bullet(Clone)"){
	
	TargetCubeDeathAnim ();


	}
}

}

function TargetCubeDeathAnim () {
	GameObject.Find("TargetCube(Clone)").transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;

}

But I still can’t work out how to try and get the scale change work in a function Update(). Any ideas?

Thanks

Paul

OnTriggerEnter can be a coroutine, do the scaling over time in there. No need for Update, it will just complicate things.

So you are only doing 1 scale at the moment - it’s probably going to be a bit too big when you use this code because you are applying it the way you are, so adjust this to work for you.

function OnTriggerEnter (bulletCollision:Collider)
{
    //Detect Collision
    if(bulletCollision.gameObject.name == "Bullet(Clone)"){

    yield TargetCubeDeathAnim ();


    }
}

function TargetCubeDeathAnim () {
    var time = 5; // 5 seconds
    var go = GameObject.Find("TargetCube(Clone)");
    while(time > 0)
    {
         go.transform.localScale += Vector3(10,10,10) * Time.deltaTime * 10;  // It will get a lot bigger now!
         time -= Time.deltaTime;
         yield null;
   }
}