I have the following code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NormalTime : MonoBehaviour {
public bool NormalTimeIsSelected;
public GameObject NormalTimeArrow;
public GameObject NormalTimeArrowSelected;
void NormalTimeFunct()
{
if (NormalTimeIsSelected == true)
{
NormalTimeArrow.SetActive(false);
NormalTimeArrowSelected.SetActive(true);
}
else
{
NormalTimeArrow.SetActive(true);
NormalTimeArrowSelected.SetActive(false);
}
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
NormalTimeFunct();
}
}
But when I try to load the NormalTimeFunct function is the On Click selector for my button, it dosen’t appear.
Try using this instead of if you’re not using Triggers (This code will work without Trigger, if it would’ve event system attached this code will not going to work) :
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class NormalTime : MonoBehaviour {
public bool NormalTimeIsSelected;
public GameObject NormalTimeArrow;
public GameObject NormalTimeArrowSelected;
//This function will work independently with a collider attached (Must).
void OnMouseDown()
{
if(NormalTimeIsSelected == false)
NormalTimeIsSelected = true;
NormalTimeFunct();
}
public void NormalTimeFunct()
{
if (NormalTimeIsSelected == true)
{
NormalTimeArrow.SetActive(false);
NormalTimeArrowSelected.SetActive(true);
}
else
{
NormalTimeArrow.SetActive(true);
NormalTimeArrowSelected.SetActive(false);
}
}
void Start () {
NormalTimeIsSelected = false;
}
}