- Home /
Collison Kills
Im wanting to make it so that when my ball collides with an object it is killed and looses a life at three lifes gone it looses game i know how to run game over just having problems with the lifes. I was wondering if some one could give me a basic code to get stated with im a little new to trying to design for android devices.
Answer by aldonaletto · Oct 12, 2011 at 10:21 PM
You must create a control script - let's call it Control.js - to hold all important variables (like health, lives, points etc.) and attach it to an empty object (or any object that's not destroyed during the level) - this could be the Control script:
static var lives = 3; // control the player lives
function Update(){ if (lives
function OnDestroy(){ Control.lives -= 1; // decrement one life when the ball is destroyed }
Ok what I have is a blackHole like item that is using the fallowing code>
var spawnPoint : Transform; var theShadow : GameObject;
function OnTriggerEnter (other : Collider) { other.gameObject.active = false; theShadow.active = false;
yield new WaitForSeconds (0.5);
other.transform.position = spawnPoint.position;
other.gameObject.active = true;
theShadow.active = true;
}
i not quite shure how i can add what u showed to this the code above is on my black hole witch causes to respawn i want it to also remove a life. The code for the lives i want on the ball so that it dies im make a ball maze game.
Ok, you're not destroying the ball, just moving it back to the spawn point. In this case, you can decrement the lives in your trigger event:
function OnTriggerEnter(other: Collider){ Control.lives -= 1; // decrement life count other.gameObject.active = false; ...You can also attach the Control script to the ball, since it's not being destroyed.