30 lines
916 B
C#
30 lines
916 B
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class MosePositionGuides : MonoBehaviour
|
||
|
|
{
|
||
|
|
public Transform MouseLongitudinalGuides;
|
||
|
|
public Transform MouseHorizonGuides;
|
||
|
|
public Transform MouseVerticalGuides;
|
||
|
|
private Transform m_Transform;
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
m_Transform = gameObject.GetComponent<Transform>();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Update is called once per frame
|
||
|
|
void Update()
|
||
|
|
{
|
||
|
|
Vector3 mousePos = Input.mousePosition;
|
||
|
|
|
||
|
|
// 将鼠标在屏幕上的位置转换为世界空间中的位置
|
||
|
|
Vector3 worldPos = Camera.main.ScreenToWorldPoint(
|
||
|
|
new Vector3(mousePos.x, mousePos.y, 8));
|
||
|
|
|
||
|
|
MouseLongitudinalGuides.position = new Vector3(worldPos.x, worldPos.y, 500);
|
||
|
|
MouseHorizonGuides.position = new Vector3(0, worldPos.y, 0);
|
||
|
|
MouseVerticalGuides.position = new Vector3(worldPos.x, 0, 0);
|
||
|
|
}
|
||
|
|
}
|