1
0

More than 5 years have passed since last update.

unity > EventSystem > ボタンを押したらToggleにフォーカスを移す > EventSystem.current.SetSelectedGameObject()を使う

Last updated at Posted at 2015-08-18
動作確認
Unity 5.1.1-f1 on MacOS X 10.8.5

UI > Buttonを押した時、UI > Toggleにフォーカスを移す方法。
EventSystem.current.SetSelectedGameObject()を使う。

以下のスクリプトをButtonのOnClickに関連付ける。

ButtonControl.cs
using UnityEngine;
using System.Collections;
using UnityEngine.EventSystems; // for EventSystem.XXX

public class ButtonControl : MonoBehaviour {

    public void OnClick() {
        Debug.Log ("clicked");

        GameObject go = GameObject.Find ("Toggle2");
        if (go) {
            EventSystem.current.SetSelectedGameObject (go);
        }
    }
}

以下はButtonをクリックした後の画像。青色の方がフォーカスが移っている。

Scene_unity_-_150818-uiGrouping_-_PC__Mac___Linux_Standalone__Personal_.jpg

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0