翻译微软官方HoloLens开发课程 凝视

xiaoxiao2021-02-28  93

把此脚本挂在 Cursor上

using System.Collections; using System.Collections.Generic; using UnityEngine; public class Cursorrr : MonoBehaviour {     MeshRenderer cursor;//光标的渲染器 void Start () {         cursor = GetComponentInChildren<MeshRenderer>();         cursor.enabled = false; } void Update () {         Vector3 HeadPosition = Camera.main.transform.position;         Vector3 HeadDir = Camera.main.transform.forward;// 头部的朝向         RaycastHit hitInfo;       if(  Physics.Raycast(HeadPosition,HeadDir, out hitInfo))         {             //表示有选中物体             cursor.enabled = true;             transform.position = hitInfo.point;//设置光标位置             //设置光标方向             transform.rotation = Quaternion.FromToRotation(Vector3.up, hitInfo.normal);         }         else         {             cursor.enabled = false;         } } }

转载请注明原文地址: https://www.6miu.com/read-73429.html

最新回复(0)