Hello! I’m pretty new to unity and training by building 2D vertical scrolling shooter something similar as Demonstar.
Anyways my problem is that I use OnTriggerEnter function to notice if players ship collides with enemyship, bullet or in this case meteor. My problem is that from time to time it seems to be triggerin twice which makes player lose two lives.
Code:
function OnTriggerEnter(otherObject: Collider){
var tempExplosion : Transform;
if(otherObject.gameObject.tag == "meteor"){
Destroy(otherObject.gameObject);
tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
if(!playerShield && playerAlive){
playerLives--;
}
}
}
When “playing” on computer there is something like 50% change of playerLives decreasing by 2, with mobile device it seems work correctly atleast there is only small change that this problem occurs. Maybe because it is running slower on mobile device?