Need a object to react different when clicked mutliple times
So I have made a clickable object for a tutorial for the game. When you first click it, most objects will disappear. When you click it again, an object will reappear. This is my code so far
using UnityEngine;
using System.Collections;
public class Explain : MonoBehaviour {
public GameObject myevents;
public GameObject friends;
public GameObject chat;
private int clicks = 2;
void OnMouseUp(){
//First click explain news
if (clicks > 1)
{
myevents.SetActive(false);
friends.SetActive(false);
chat.SetActive(false);
clicks = clicks + 1;
}
else (clicks > 2){
myevents.SetActive(true);
}
}
}
At first, it would do both function in a single click, and now it says Assets/ExplainPhone/Scripts/Explain.cs(21,34): error CS1525: Unexpected symbol `{'
How do I fix this error, and make it so that the else functions only reacts on a second click? I just started working with variables, so please keep it simple :D
Comment
Answer by Baste · Dec 15, 2015 at 11:37 AM
"else" needs to be "else if", since you're using it as an else if.
if you want the SetActive call to only happen on the second click, just check for equality with two:
else if (clicks == 2) {
myEvents.SetActive(true);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612052707im_/https://answers.unity.com/themes/thub/images/avi.jpg)