NGUI获取当前的点击对象 UGUI获取当前的点击对象

NGUI的UICamera中定义了一个内部类MouseOrTouch表示当前的输入设备:鼠标,Touch,或是游戏杆。

//begin源代码// 

public class MouseOrTouch
 {
  public Vector2 pos;    // Current position of the mouse or touch event
  public Vector2 delta;   // Delta since last update
  public Vector2 totalDelta;  // Delta since the event started being tracked

  public Camera pressedCam;  // Camera that the OnPress(true) was fired with

  public GameObject current;  // The current game object under the touch or mouse
  public GameObject pressed;  // The last game object to receive OnPress

  public float clickTime = 0f; // The last time a click event was sent out

  public ClickNotification clickNotification = ClickNotification.Always;
  public bool touchBegan = true;
  public bool pressStarted = false;
  public bool dragStarted = false;
 }

//end源代码//

在MouseOrTouch中定义了当前点击的物体:current

当我们点击某个物体时,只需要调用UICamera.currentTouch.current即可获取具体点击的是哪个物体。

这个方法是为了在不同的按钮使用同一点击事件时非常有效。

 转载:http://t.csdn.cn/s2pzb 

UGUI获取当前的点击对象

EventSystem.current.currentSelectedGameObject  需引用命名空间

using UnityEngine.EventSystems;

需要在对应UI上添加 Selectable 组件。

转载:http://t.csdn.cn/Wjd8q

//GameObject obj = EventSystem.current.currentSelectedGameObject;//只对UGUI起作用
//GameObject obj = GameObject.FindWithTag("Sprite");//当有多个对象时默认点击的是第一个
//bool b = UICamera.Raycast(Input.mousePosition);//射线检测 为bool值判断
//GameObject obj = UICamera.currentTouch.current;//对NGUI器作用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值