problem with touch code android

Hello,

I have a problem with this piece of code:

function Update(){
 for (var touch : Touch in Input.touches){
  if (guiTexture.HitTest (touch.position)){
  	guiTexture.color = overColor;
  if (partClicked == true){
    Debug.Log("uit!");
    Emitter.GetComponent(ParticleEmitter).emit= false;
    partClicked = false;
  }
  if (partClicked == false){
    Debug.Log("aan!");
    Emitter.GetComponent(ParticleEmitter).emit= true;
    partClicked = true;
  }
  }
 }
 }
}

I have a button and when i click on it, i want to turn the particles on, and when i click on it again the particles must go off. This code is attached on a GUI texture.

I know what the problem is (when i touch the button it will execute the 2 “if” commands), so the are always false. And when i keep touching the button it keeps executing the code. How can i make sure that the code is executed only once? no matter how long i keep pressing the button.

tnx in advance!

Change the “if (partClicked == false)” to “else if (partClicked == false)

From what I understand, you are doing unnecessary calls and assignments. Is it not something like this you want;

function Update()
{
    for (var touch : Touch in Input.touches)
    {
        if (guiTexture.HitTest (touch.position))
        {
  	        guiTexture.color = overColor;
            
            partClicked = !partClicked;
            Emitter.GetComponent(ParticleEmitter).emit = partClicked;
       }
  }

thx! i’ll give it a go when i get home.
I already figured out the else if. And the touchPhase.began , stationary and ended.
That was also a part of my problem.