世界坐标系转换为屏幕坐标
屏幕坐标转世界坐标
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
print(Camera.main.WorldToScreenPoint(this.transform.position));
}
// Update is called once per framevoid Update(){if(Input.GetMouseButtonDown(0)){GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Cube);Vector3 v = Input.mousePosition;v.z = 20;obj.transform.position = Camera.main.ScreenToWorldPoint(v);}}
}
如果觉得《Unity中屏幕坐标与世界坐标之间的转换》对你有帮助,请点赞、收藏,并留下你的观点哦!