LoginSignup
16
14

More than 5 years have passed since last update.

Unity4.6オープンβでボタン機能を試してみた

Last updated at Posted at 2014-08-21

4.6オープンβはここからダウンロード
http://unity3d.com/unity/beta/4.6

目玉はやはり「uGUI」ということで、ボタン機能を試してみた

概要

「ボタンを押したら反応」まで

流れ

1.GameObject→UI→ButtonでButtonオブジェクトを追加
2.GameObject→CreateEmptyで空のGameObjectを追加し"UItest"と命名
3.空のGameObjectにスクリプトを追加しTest関数を作成
GameObject_UItest.png
4.InspectorでButton(Script)にあるOn Click()で2番で作成した"UItest"を選択し、Test関数を選択
On_Click.png

結果

実行して"Button"を押すと"Button Push!"がConsoleに出力される
Screen.png

Consoleに文字列が出力される
Console.png

感想

感触的には、NGUIとやり方は同じなので、NGUIを触ったことがある人は
移行しやすい印象を受けた

ただ、"空GameObjectにScriptをつけて、それをButtonにつける"というのは
慣れていない人には分かりにくい気がするのは変わらず。

あと、NGUIと違うのはコリジョン設定を行わなくても良い所ですね。

使用したスクリプト

Buttonを押した時に動作するスクリプト

Test.cs
using UnityEngine;
using System.Collections;

public class ButtonPush : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    // ボタンを押した際に呼ばれる関数
    public void Test()
    {
        // ボタンが押した際に出力
        print("Button Push!");
    }
}
16
14
1

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
16
14