0
我的场景中有一个立方体,我想随着玩家的触摸旋转并拖动它。这里是代码Unity5 C#:如何通过触摸拖动来旋转游戏对象
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Physics.Raycast (ray, out hit);
if(Input.GetMouseButton(0) && hit.collider.name == "Cube")
{
xDeg -= Input.GetAxis("Mouse X") * speed * friction;
yDeg += Input.GetAxis("Mouse Y") * speed * friction;
fromRotation = cube.transform.rotation;
toRotation = Quaternion.Euler(yDeg,xDeg,0);
cube.transform.rotation = Quaternion.Lerp(fromRotation,toRotation,Time.deltaTime * lerpSpeed);
}
我能够做到100%,问题是我已经把其他几个游戏对象与立方体的每面墙撞机。我想要的只是玩家能够旋转魔方并通过点击每个墙上的特定游戏对象来执行一些操作。这里是代码
if (Input.GetMouseButtonUp(0))
{
Ray ray1 = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast (ray1, out hit)) {
if (hit.collider.name == "ABC") {
//Perform action specific to ABC
}
}
}
其余的现在,如果我尝试转动它运行ABC立方体(因为肯定光线投射工作,它假设是)。我无法弄清楚我是如何实现这一点的,玩家可以通过触摸和拖动来旋转立方体,以及通过轻敲同一立方体的墙壁来执行某些操作。
你用设备检查过吗?你有没有试过这个... –