Help us understand the problem. What is going on with this article?

Unityの新GUIでマウスオーバー判定サンプル

More than 3 years have passed since last update.

Unity uGUIでマウスオーバー

スマートフォン上でも動作します。

サンプルコード

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;

[RequireComponent( typeof( Image ) )]
public class TapOverComponent : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
    public Image image { get { return GetComponent<Image>(); } }

    // オブジェクトの範囲内にマウスポインタが入った際に呼び出されます。
    // this method called by mouse-pointer enter the object.
    public void OnPointerEnter( PointerEventData eventData )
    {
        image.color = Color.red;
    }

    // オブジェクトの範囲内からマウスポインタが出た際に呼び出されます。
    // 
    public void OnPointerExit( PointerEventData eventData )
    {
        image.color = Color.white;
    }
}

主な要素

要素 概要
IPointerEnterHandler OnPointerEnterが定義されている
OnPointerEnter uGUIオブジェクトの範囲内にマウスポインタが入った際に呼び出される
IPointerExitHandler OnPointerExitが定義されている
OnPointerExit uGUIオブジェクトの範囲内からマウスポインタが出た際に呼び出される
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした