- Home /
How to ADD one Buttons.onClick events to another Buttons.onClick?
Simply put, I have a system right now that copies one button's onClick events into another button, but I need to change it so that it can add one button's onClick events to another button, retaining the events that the second button started out with.
I have tried looping through one button's onClick events using onClick.GetPersistentEventCount and then referencing onClick.GetPersistentMethodName and onClick.GetPersistentTarget, but that doesn't seem to be working, so any help here would be appreciated.
Thank you.
Answer by kalacia · Jul 30, 2016 at 01:11 PM
I work with something similar in my game. Although im not the best.. yet ;)
I use a cs file to store my gloabal vars and then reference and do the functions in other c# files. This takes the external file/script you referenced, then using dot notation. References the var that you set in the other file. Allowing you to alter a single files vars from multiple input sources. I have snipped down an example of my code (not saying its pretty or the best, maybe ill learn something too)
// material storage in GameVars.cs
public int wood = 0;
public int stone = 0;
public int food = 0;
// turn.cs
using UnityEngine;
using System.Collections;
public class Turn : MonoBehaviour {
public GameVars gamevars;
public UnityEngine.UI.Text woodDisplay;
public void onturn (){
gamevars.woodincome = gamevars.lumberfarmbuilt * (gamevars.prod_lumberfarm * gamevars.tech_lumberfarm) ;
gamevars.wood = gamevars.wood + gamevars.woodincome;
}
Thank you $$anonymous$$alacia, but I think the solution you've provided is more for an overall data management/exposure system while the issue I've presented is more explicitly about adding OnClick functionality from one button to another.