- Home /
Help with game, stopping player cheating (script help)
I am using 2 scripts (kindly helped by "immesivegamer") (see scripts below), in my breakout style game.
The problem I have is that with the current setup, the player can still press "space" and fire another ball whilst one is already in game. So the player can fire one ball hit a few blocks then if the ball is going to hit the floor they can press "space" and fire another, saving losing a life! (good for testing the game though! hehe)
Is there a way to disable the pressing of the spacebar until the ball in play is destroyed (by hitting the floor when they miss)? or something to add to the script/scripts to achieve this?
any help/suggestions appriciated
---------- Script on my shoot object: ----------
var thePrefab : GameObject;
var MaxObjectCount = 0;
function Update () {
if(Input.GetButtonDown("Jump")){
var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
instance.name = "Bullet";
MaxObjectCount += 1;
if(MaxObjectCount == 2){
Destroy(GameObject.Find("Bullet"));
MaxObjectCount -=1;
}
}
}
---------- Script on my floor: ---------- var shootObject : GameObject;
function OnCollisionEnter ( collision : Collision) {
if (collision.collider.name == "Bullet"){
var shootScript : testshootscript = shootObject.GetComponent(testshootscript);
Destroy (GameObject.Find("Bullet"));
shootScript.MaxObjectCount -= 1;
lives.LIVES -= 1;
//adding in to destroy Bullet_super if hits floor (without removing a life)
if (collision.collider.name == "Bullet_super"){
Destroy (GameObject.Find("Bullet_super"));
}
}
}
Answer by rutter · Mar 28, 2012 at 10:05 PM
Looks like you're already tracking the number of bullets. Why not just check if that's greater than zero in the same spot you're checking for user input?
hi rutter, I don't understand, could you please explain what you mean? (i'm newbie at scripting trying to wrap my head around it all)
Here:
if(Input.GetButtonDown("Jump")){
You could change this to:
if(Input.GetButtonDown("Jump") && $$anonymous$$axObjectCount < 1){