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

时间:2019-03-24 14:39:54

标签: c# unity3d material gameobject

我要从预制实例化一个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

1 个答案:

答案 0 :(得分:0)

“ ball.scale”看起来在一个轴上的值可能为零,这使对象变平,从而可能使外观混乱。

检查传入对象的比例值。