Unity3D localscale问题

时间:2014-02-03 22:24:49

标签: c# unity3d transform scale

以下代码:

Debug.LogWarning("updating scale fix, scalefactor: "+scaleFactor+" - Current scale is: "+cell.transform.localScale.x);
cell.transform.localScale.Set (scaleFactor,scaleFactor,scaleFactor);
Debug.LogWarning("Scale after fix: " + cell.transform.localScale.x);

产生以下输出:

updating scale fix, scalefactor: 0.9 - Current scale is 0.8921105
UnityEngine.Debug:LogWarning(Object)

Scale after fix: 0.8921105
UnityEngine.Debug:LogWarning(Object)

有什么想法吗?我只是假设由于这些事情是在彼此之后发生的,因此应该更新比例。或者在框架完成后会发生这种情况吗?

感谢任何帮助。

1 个答案:

答案 0 :(得分:5)

localScale是一个属性,因此它返回真实localScale的副本(Vector3是一个结构) 试试cell.transform.localScale = new Vector3 (scaleFactor, scaleFactor, scaleFactor);cell.transform.localScale = Vector3.one * scaleFactor;