- Home /
Where can a Lerp be used?
I'm trying to make a lerp for one of my enemies once its trigger is activated. So I have to put it in the function that dictates that, which is a collision function.
Does lerp only work in function Update? Or do I have something wrong?
Here are the relevant parts of my script:
var thePrefab: GameObject;
var enemyActive : boolean = true;
var jelReg : Material;
var jelShock : Material;
var duration = 60.0;
private var coin : GameObject;
private var player : PlayerScript;
function Start(){
player = GameObject.FindWithTag("Player").GetComponent(PlayerScript);
renderer.material = jelReg;
}
function Update () {
}
function OnCollisionEnter(theCollision : Collision){
if(player.Diamond == true){
Destroy(gameObject.transform.root.gameObject);
coin = Instantiate(thePrefab, transform.position, Quaternion.identity);
}
if(player.Diamond == false){
if(theCollision.gameObject.tag == "Player"){
yield WaitForSeconds(2);
gameObject.collider.isTrigger = true;
enemyActive = true;
var lerp : float = Mathf.PingPong (Time.time, duration) / duration;
renderer.material.Lerp (jelReg, jelShock, lerp);
yield WaitForSeconds(3);
gameObject.collider.isTrigger = false;
renderer.material = jelReg;
enemyActive = false;
}
}
}
it's probably something small, or that lerps just can't be used outside of the update function. Whatever the case, please help!
Answer by Entrio · Dec 25, 2013 at 08:48 AM
OnCollisionEnter gets called only, you guessed it, on collision enter. it gets executed once.
lerping is a process over time, so you will need a way to constantly update the lerp over time. An update or fixed update is the perfect place to do this.
have a read here, it describes it a little bit better.
I can't seem to find useful information in that link. There's a download for a program, but I'm not about to risk that... anyways, ok, so it cannot be executed in a collisionenter function. Does that mean I have to create a new function with the lerp information in it, and then link it that way? I tried that and it didn't work...
How do I make it so that a lerp can be used once a box collider triggers a trigger to be true?
Answer by Indie_Solo · Jun 25, 2014 at 01:31 PM
have you tried on collision enter, then on collision stay. [http://docs.unity3d.com/ScriptReference/Collider.OnCollisionStay.html][1]
Your answer
Follow this Question
Related Questions
"Unknown resolve error" 2 Answers
Error with function OnTriggerXXX 1 Answer
Character Controller and moving/lerping object collisions 0 Answers
Problem with lerping several objects to positions. 2 Answers