Is there a way to disable a function? In my scene I have a pot that goes back and forth (through Mathf.PingPong) when it collides with an object falling on the other to increase the rate to increase but I must eliminate the instruction present in the Update () function; advice?
You can disable specific parts “within” a script with a simple boolean, so just set it to true or false and use if(boolean == true) to stop the function from doing stuff.
If you want to disable the whole script, you can use yourscript.enabled = false;
I tried to do so but I should put the second function in the update ();
#pragma strict
function Start () {
}
function Update () {
// Set the x position to loop between 0 and 3
Muovi();
if(Muovi == false){
MuoviDue();
}
}
function Muovi(){
transform.position = Vector3(
Mathf.PingPong(Time.time, 5)*8.5, transform.position.y, transform.position.z);
}
function MuoviDue(){
transform.position = Vector3(
Mathf.PingPong(Time.time, 5)*12, transform.position.y, transform.position.z);
}
function OnTriggerEnter(other:Collider){
Destroy(other.gameObject);
Muovi == false;
MuoviDue == true;
}