unity Instantiate实例化物体后出现scale改变

最近在做的东西大部分都要用到instantiate, 实例化某个prefab物体,实例化的物体若没有指定父物体,就会自动生成到根目录下。

这是出现了一个问题,当实例化物体后,更改parent值,这时,实例化物体的scale值会产生相应的改变

有两种解决办法

1、instantiate本身可以有父物体参数  Instantiate<T>(T original, Vector3 position, Quaternion rotation, Transform parent),

这样实例化出来的物体不会出现scale中的改变(因为没有在外部更改父物体,一次性成品,安全

1  Instantiate(twoDPreb, twoDPreb.transform.position, twoDPreb.transform.rotation, this.transform.Find("Panel").transform);

2、如果是实例化后,更改父物体导致scale值更改,也可以在下面更改实例化物体的localScale的值来更改其scale值

1  GameObject obj = Instantiate(twoDPreb, twoDPreb.transform.position, twoDPreb.transform.rotation);
2  obj.transform.SetParent(this.transform.Find("Panel").transform);
3  obj.transform.localScale = new Vector3(1, 1, 1);
原文地址:https://www.cnblogs.com/Small-Transparent/p/11022633.html