- Home /
mouse click obj to initiate action, then locking the obj so action cant be repeated
when i click on the target object it starts its partical animation and registers that one target has been activated, the issue im having is that the player can hit the same target over and over and it will register that multiple targets have been hit, how do i fix my script to show that one target has been hit and that the hit target can no longer be affected by the player once activated?
here is the obj partical animation script
var fire: GameObject;
var smoke: GameObject;
function OnMouseDown(){
var campSound: AudioSource = GetComponent(AudioSource);
campSound.Play();
var flame: GameObject = Instantiate(fire,transform.position, Quaternion.identity);
var flameEmitter: ParticleEmitter = flame.GetComponent(ParticleEmitter);
flameEmitter.emit=true;
var smoke: GameObject = Instantiate(smoke,transform.position, Quaternion.identity);
var smokeEmitter: ParticleEmitter = smoke.GetComponent(ParticleEmitter);
smokeEmitter.emit=true;
GameObject.Find("Clock").GetComponent("Clock script").remainedTarget-=1;
and this is the timer script, once the time is up the player is taken to the winning or losing pages(that part works my issue is making it so the player CANT hit the same target over and over in order to win)im not sure if this part of my script needs editing but to be safe ill include it.
function TimeIsUp(){
lives = (PlayerPrefs.GetInt("Player Lives")) - 1; //*** Get the value of “Player lives” and -1
PlayerPrefs.SetInt("Player Lives", lives ); // *** and assign it to the local lives variable.
if (remainedTarget == 0) { Application.LoadLevel(3);} // *** Winning Condition
else if (lives == 0) { Application.LoadLevel(4); } // *** Losing Condition
else {
Application.LoadLevel(1); // *** Reload the current Scene
}
}
Answer by Gamer2470 · Mar 03, 2012 at 03:23 AM
try adding an OnMouseUp Fuction too(disregard last answer)
Answer by Blazor Ramone · Mar 03, 2012 at 05:27 AM
Add a private bool, initialize it to false and set it to true when the target it hit. Check this bool before you do the other stuff..
OnMouseDown()
{
if(!hit)
{
hit = true;
//do all other stuff here
}
}