「Unity/UIクリック」の版間の差分
提供: 初心者エンジニアの簡易メモ
行5: | 行5: | ||
EventTrigger.Entry entry = new EventTrigger.Entry(); | EventTrigger.Entry entry = new EventTrigger.Entry(); | ||
entry.eventID = EventTriggerType.PointerClick; | entry.eventID = EventTriggerType.PointerClick; | ||
− | |||
entry.callback.AddListener(delegate { | entry.callback.AddListener(delegate { | ||
− | + | SetColor(colorName); | |
}); | }); | ||
trigger.triggers.Add(entry); | trigger.triggers.Add(entry); | ||
</pre> | </pre> |
2020年5月15日 (金) 19:37時点における版
UIにクリックイベントを追加
GameObject colorImage = GameObject.Find("ColorImage"); EventTrigger trigger = colorImage.AddComponent<EventTrigger>(); EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerClick; entry.callback.AddListener(delegate { SetColor(colorName); }); trigger.triggers.Add(entry);