After creating the GameObject in the Hierarchy, I added a Button component.
And I set the Transtion setting to Animation.
And we created an animation by adding Sprite image for Normal, Highlited, Pressed, and Disabled functions.
Below is a picture of the setting.
I have succeeded in finding the GameObject by applying the Find function to the script.
The script looks like this:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using wp.events;
public class ButtonController : MonoBehaviour, IWordGame
{
private Button start_btn, play_btn;
void Awake()
{
}
void Start ()
{
WordGameEventManager.Instance.addEvent(onEventHandler); // 이벤트 추가
start_btn = GameObject.Find("start_btn").GetComponent<Button>();
start_btn.onClick.AddListener(()=> onClickStartBtn(start_btn));
play_btn = GameObject.Find("btn_play").GetComponent<Button>();
Debug.Log("play_btn Find >> " + play_btn);
play_btn.onClick.AddListener(() => onClickPlayBtn(play_btn));
}
void Update ()
{
}
public void onEventHandler(object obj, EventArgs e)
{
WordGameEvent wg_evt = e as WordGameEvent;
//Debug.Log("ButtonController was Receive Event >> " + wg_evt.eventType);
}
public void onClickStartBtn(Button sbtn)
{
//Debug.Log("You Click Start_Button");
WordGameEventManager.Instance.dispatchEvent(sbtn, EventTypes.PUSH_START_BTN); // 이벤트 보냄
}
public void onClickPlayBtn(Button pbtn)
{
Debug.Log("You Click Play_Button");
Hashtable data = new Hashtable();
data.Add("word", WordGameManager.Instance.getQuizQuestion());
Debug.Log("data value >> " + data);
WordGameEventManager.Instance.dispatchEvent(pbtn, EventTypes.PUSH_WORD_BTN, data);
}
}
If I click the button, the Pressed Animation does not occur and the onClickPlayBtn function does not execute.
What is wrong and not running? I would really appreciate it if you would advise.
Note that the script above is currently in MainCamera.