using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RayTest : MonoBehaviour
{
private Vector3 target;
bool b = false;
void Start ()
{
}
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
//射线检测
//返回bool值,检测射线与物体是否有交点
//bool res = Physics.Raycast(ray, out hit);
//射线检测 第二种
// << 左移运算符 也有 >> 右移运算符 2 << 1
// 00000001 00000100
//左移多少位就是乘以2的几次方
// >> 右移,就是除以2的几次方
//返回bool值,检测射线与物体是否有交点,检测范围500,只检测第八层(地面那层,不检测墙)
bool res = Physics.Raycast(ray, out hit,500f,1 << 8);
// 或 bool res = Physics.Raycast(ray, out hit,500f,1 << LayerMask.NameToLaye
Unity(一)射线--物体跟随鼠标点击位置移动
最新推荐文章于 2024-05-23 15:39:30 发布