Answers for "unity onclick addlistener"

C#
2

unity onclick addlistener

public int index;  
private Button myselfButton;   

void Start()  
{      
  myselfButton = GetComponent<Button>();      
  myselfButton.onClick.AddListener(() => actionToMaterial(index));  
}   

void actionToMaterial(int idx)  
{      
  Debug.Log("change material to HIT  on material :  " + idx);  
}

void Destroy()
{
  myselfButton.onClick.RemoveListener(() => actionToMaterial(index));
}
Posted by: Guest on May-06-2020

Code answers related to "unity onclick addlistener"

C# Answers by Framework

Browse Popular Code Answers by Language