zoukankan      html  css  js  c++  java
  • 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);
  • 相关阅读:
    对象实例化内存布局与访问定位
    方法区

    本地方法栈
    本地方法接口
    虚拟机栈
    程序计数器
    运行时数据区概述及线程
    自学》2.网页弹窗计算商品价格
    自学》1.用网站发邮件
  • 原文地址:https://www.cnblogs.com/Small-Transparent/p/11022633.html
Copyright © 2011-2022 走看看