error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'.

屏幕快照 2016-06-19 16.15.26.png

在Gameobject设置坐标位置的报错

error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'. Consider storing the value in a temporary variable

报错的代码是这样写的,为了修改x的值

GameObject obj =	GameObject.Find("obj"+i);
obj.transform.position.x = 100.0f;

找了找,应该这样设置才可以

GameObject obj =	GameObject.Find("obj"+i);
Vector3 pos = obj.transform.position;
pos.x = 100.0f;
obj.transform.position = pos;

参考文章

  1. error CS1612: Cannot modify a value type return value of `UnityEngine.Transform.position'.

Last modification:January 1st, 1970 at 08:00 am
如果看了这个文章可以让你少加会班,可以请我喝杯可乐
已打赏名单
微信公众号

Leave a Comment