将局部比例设置为实例化的gameObject时,它会丢失材料

问题描述 投票:2回答:1

我正在从prefab实例化一个gameObject,我想用代码设置局部比例,但是当我将transform.localScale设置为gameObject时,它会丢失材料并变为黑色。

public GameObject ballObject;    

 public GameObject GetBall(Ball ball)
     {
         GameObject gameObject = Instantiate(ballObject, ball.position, Quaternion.identity);
         gameObject.transform.localScale = ball.scale; // actually, this line destroys the material
         gameObject.tag = Constants.ballTag;

         return gameObject;
     }

enter image description here

enter image description here

c# unity3d material gameobject
1个回答
0
投票

看起来'ball.scale'在一个轴上的值可能为零,这会使对象变平,这会以这种方式弄乱外观。

检查传入对象的比例值。

© www.soinside.com 2019 - 2024. All rights reserved.