我试图在实例化对象时随机旋转它们。但是我很难仅在z轴上旋转。

GameObject currentcicrle = (GameObject)Instantiate (circlePointPrefab);//instaiate object
currentcicrle.transform.parent = parent;
currentcicrle.GetComponent<Renderer>().material = currentLineRender.GetComponent<LineRendererAttributes> ().material;
currentcicrle.transform.position = position;

currentcicrle.transform.rotation = Random.rotation;

最佳答案

currentcircle.transform.rotation = Quaternion.Euler(0.0, 0.0, Random.Range(0.0, 360.0);


要么

currentcircle.Rotate(0.0, 0.0, Random.Range(0.0, 360.0));


Previous Answer

关于c# - unity绕z轴旋转,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57716631/

10-12 14:40