So I want a collision from gameobjects ‘Player’ and ‘Ball’ to effect a variable in my timer script.
Is there a way to detect a collision between two objects on a separate script? I know how to detect a collision if the script is attached to the gameobject directly, but I need my collision detection to be on my timer script so I can effect it’s variables.
public class Timer : MonoBehaviour {
public float timer = 300;
public float timerSpeed = 100;
void OnGUI () {
timer -= Time.deltaTime*timerSpeed;
if (timer > 0)
guiText.text = timer.ToString("F0");
else
guiText.text = "GAME OVER";
}
void OnCollisionEnter(Collision thecollision){
if(thecollision.gameObject.name == "Player")
timerSpeed = 50;
}
}
Anyway this is what I know what to do.
Very new to all this so any help would be most appreciated.