- Home /
How to add ur own function/script to event trigger in canvas?
I have a Jump button in canvas that I wanna reference to my own script when someone touches it (mobile). I added my own script to the button object and an event trigger component. When I tried to select my script in the event trigger component I couldn't see my own function... (Canvas-> JumpButton->event trigger-> add new event type-> pointer click->button->?). Do I have to use a function from Unity or can I use my own? Thanks in advance!
Can you provide your script? Also make sure your function is public.
Answer by zereda-games · Mar 10, 2019 at 03:44 PM
private Button ClearPurchasingDataButton;
private string ClearPurchasingDataButtonTag = "ClearPurchasingDataButton";
void Awake()
ClearPurchasingDataButton = GameObject.FindGameObjectWithTag(ClearPurchasingDataButtonTag).GetComponent<Button>();
ClearPurchasingDataButton.onClick.AddListener(OnClearUnityPurchasingPath);
}
[MenuItem("Editors/ZeredaGamesEngine/Game Making Tools/Delete/Clear Unity Purchasing Path", false, 1)]
public static void OnClearUnityPurchasingPath()
{
if (EditorUtility.DisplayDialog("Clear Unity Purchasing Entries", "Are you sure you want to clear Unity Purchasing data for this project? ", "Clear", "Skip"))
{
string unityPurchasingPath = System.IO.Path.Combine(System.IO.Path.Combine(Application.persistentDataPath, "Unity"), "UnityPurchasing");
if (System.IO.Directory.Exists(unityPurchasingPath))
{
System.IO.Directory.Delete(unityPurchasingPath, true);
}
if (Instance.DebugMode)
{
string message = System.DateTime.Now.ToString();
Debug.Log("[" + message + "] [UNITY PURCHASING PATH CLEARED]");
}
}
}
Answer by kamran-bigdely · Mar 10, 2019 at 03:53 PM
Your function that is going to be called by event trigger should be:
public
have a void return type
take one or no parameter.
it doesn't Need to be public.... it's just less coding..
Yes it is but I cant see it. Do I maybe need to make a reference?
ps: Instance.Debug$$anonymous$$ode is a Static Debug$$anonymous$$ode on that script...