当前位置:网站首页>Unity关于本地坐标和世界坐标之间的转换

Unity关于本地坐标和世界坐标之间的转换

2022-06-24 19:19:00 charlsdm

常用的就是transformPoint这一类的API引用了
下面附上我写的代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CreateCube : MonoBehaviour
{
    
    // Start is called before the first frame update
    void Start()
    {
    
        
    }

    // Update is called once per frame
    void Update()
    {
    
        
    }

    [ContextMenu("左前方创建空物体")]
     void TestFun1()
    {
    
        // Vector3 pos = this.transform.TransformPoint(new Vector3(-1, 0, 1));
        GameObject obj = new GameObject("hello");
        obj.transform.position = this.transform.TransformPoint(new Vector3(-1, 0, 1));

    }

    [ContextMenu("勉强创建3个球体")]
    void TestFun2()
    {
    
        GameObject objOne = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        objOne.transform.position = this.transform.TransformPoint(new Vector3(0, 0, 1));

        GameObject objTwo = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        objTwo.transform.position = this.transform.TransformPoint(new Vector3(0, 0, 2));

        GameObject objThree = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        objThree.transform.position = this.transform.TransformPoint(new Vector3(0, 0, 3));


    }
}
原网站

版权声明
本文为[charlsdm]所创,转载请带上原文链接,感谢
https://blog.csdn.net/charlsdm/article/details/125429387