您当前的位置: 首页 >  unity

云小川

暂无认证

  • 5浏览

    0关注

    78博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

unity 射线拾取物品

云小川 发布时间:2021-10-22 11:39:30 ,浏览量:5

using UnityEngine;
using System.Collections;
public class RayTest : MonoBehaviour { 
       // Use this for initialization  
       void Start () { 
      }  
       // Update is called once per frame  
    void Update ()  
     { 
       if(Input.GetMouseButton(0))  
         { 
              Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);//从摄像机发出到点击坐标的射线  
              RaycastHit hitInfo;  
//
LayerMask.GetMask("Obj")
        if(Physics.Raycast(ray,out hitInfo))  
            { 
                Debug.DrawLine(ray.origin, hitInfo.point);//划出射线,只有在scene视图中才能看到  
                GameObject gameObj = hitInfo.collider.gameObject;  
                Debug.Log("click object name is= " + gameObj.name);  
             if(gameObj.tag == "boot")//当射线碰撞目标为boot类型的物品 ,执行拾取操作  
               { 

                    Debug.Log("要拾取的物品!");  
               }  
            }  
        }  
     }  
 } 
   
【Unity】鼠标划入划出检测
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class button01 : MonoBehaviour,IPointerEnterHandler,IPointerExitHandler
{
  public void OnPointerEnter(PointerEventData eventData)
    {
        Debug.Log("进入");    
    }
    //鼠标离开
    public void OnPointerExit(PointerEventData eventData)
    {
       
        Debug.Log("出去");
    }
 }

关注
打赏
1663746399
查看更多评论
立即登录/注册

微信扫码登录

0.1370s