Hello. I am using unity 5 beta pro. I want to make button (FROM UI) onclick to do this if funtion:
if(database.money == 5)
{
cannon2.SetActive(true);
}
How can i do that?
Hello. I am using unity 5 beta pro. I want to make button (FROM UI) onclick to do this if funtion:
if(database.money == 5)
{
cannon2.SetActive(true);
}
How can i do that?
So add your button (I assume you know how to do this). Then create a script for eg :
using UnityEngine;
using UI;
public class Test : MonoBehaviour
{
public void DoSomething()
{
if(database.money == 5)
{
cannon2.SetActive(true);
}
}
}
Important to make the function public. Then you attach this script to your button in the insoector. Then in the Button script that is automatically attached to the button, select the little + sign at the bottom where it has the section OnClick(). Grab your button form the hierarchy and drag and drop it into the area saying None(object). Then click on the button nect to that that says “No Function” and you will see the function there from you attached script. Select it and you’re done.