使用预制体创建实例对象后添加父节点,预制体坐标会自动转换为与未添加父节点前的相对坐标,此时添加父节点后应当更改其局部坐标
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public GameObject tempObject;
public GameObject CubeObject;
// Start is called before the first frame update
void Start()
{
GameObject temp = (GameObject)GameObject.Instantiate(tempObject);
temp.transform.SetParent(CubeObject.transform);
temp.transform.localPosition = Vector3.zero;
//temp.transform.position = Vector3.zero;//错误
}
// Update is called once per frame
void Update()
{
}
}
预制体坐标为(0,0,0)
未更改局部坐标时:

更改局部坐标后:

Unity预制体添加父节点后坐标处理
博客介绍了在Unity中使用预制体创建实例对象并添加父节点的情况。添加父节点后,预制体坐标会自动转换为相对坐标,此时需要更改其局部坐标,并给出了预制体初始坐标及未更改和更改局部坐标的相关说明。
9618

被折叠的 条评论
为什么被折叠?



