求问实现以下c#脚本怎么写

卋枍 2020-07-01 06:34:19
用射线检测、实现:三个Cube,点击其中一个,如果该Cube静止不动、则该Cube就会旋转,其他Cube停止旋转;如果该Cube正在旋转,则本方块停止旋转,其他方块不动。
...全文
61407 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Minikinfish 2020-07-23
  • 打赏
  • 举报
回复
你自己都写出来了,哪里不对吗?
crazyapp 2020-07-02
  • 打赏
  • 举报
回复
public GameObject[] _Cubes; public int _Speed = 30; bool isRotation1 = false; bool isRotation2 = false; bool isRotation3 = false; private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; bool isHit = Physics.Raycast(ray, out hit); if (isHit) { if (hit.transform.name =="Cube1") { Debug.Log("click cube 1"); if (isRotation1) isRotation1 = false; else isRotation1 = true; isRotation2 = false; isRotation3 = false; } else if (hit.transform.name == "Cube2") { Debug.Log("click cube 2"); if (isRotation2) isRotation2 = false; else isRotation2 = true; isRotation1 = false; isRotation3 = false; } else if (hit.transform.name == "Cube3") { Debug.Log("click cube 3"); if (isRotation3) isRotation3 = false; else isRotation3 = true; isRotation2 = false; isRotation1 = false; } } } if (isRotation1) _Cubes[0].transform.Rotate(Vector3.forward * _Speed * Time.deltaTime); if (isRotation2) _Cubes[1].transform.Rotate(Vector3.forward * _Speed * Time.deltaTime); if (isRotation3) _Cubes[2].transform.Rotate(Vector3.forward * _Speed * Time.deltaTime); }

2,537

社区成员

发帖
与我相关
我的任务
社区描述
Unity3D相关内容讨论专区
游戏unity 技术论坛(原bbs)
社区管理员
  • Unity3D
  • 芝麻粒儿
  • 「已注销」
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

Unity3D社区公告:

  1. 社区致力于解决各种Unity3D相关的“疑难杂症”。
  2. 社区不允许发布与Unity3D或相关技术无关内容。
  3. 社区版主邀请各位一道为打造优秀社区不懈努力。

试试用AI创作助手写篇文章吧