Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Hi Carlkbh.

How do you refer to this object?

Do you declare it publicly and attach it in Unity or do you find it with a tag or name?

If you wont mind showing us the whole script can help a lot more than just a function.

(1 edit)

i used the eventtricker function

Take a look at the code from the manual.


using UnityEngine; 
using UnityEngine.UI; 
using System.Collections;
public class ClickExample : MonoBehaviour 
{ 	
  public Button yourButton; // Put your button in here
  void Start () 
  { 		
    Button btn = yourButton.GetComponent<Button>(); 		
    btn.onClick.AddListener(TaskOnClick); 
    //When the button gets clicked/pressed it will call TaskOnClick() function below	
  }
  void TaskOnClick()
  { 		
    Debug.Log ("You have clicked the button!"); 	
  } 
}
I hope this helps.
I've struggled with this same topic a while ago 
and this helps