简体   繁体   English

与Unity3D中的OnMouseUp()等效

[英]Equivalent of OnMouseUp() in Unity3D

I basically have this code. 我基本上有这段代码。 I got performance errors in unity3d when I tried to use OnMouseUp() function. 当我尝试使用OnMouseUp OnMouseUp()函数时,在unity3d中出现性能错误。 I have no idea how to use Touch functions for android. 我不知道如何为Android使用Touch functions

void OnMouseUp()
{
    DetectCollider.IfInMain = false;
    DetectCollider.Score = 0.00f;
    MainMenux.SetActive(false);
    Mech.transform.rotation = Quaternion.Euler(270, 180, 0);
    DetectCollider.Speed = 100;
    ScoreCountTurn = true;
}

Try something like this. 尝试这样的事情。 It should work for android also. 它也应该适用于android。

  void Update() {
    if (Input.GetMouseButtonUp(0)) 
    {
        DoStuff();
    }
  }

Or you can use Input.GetTouch(), and then check TouchPhase, instead of GetMouseButtonUp(). 或者,您可以使用Input.GetTouch(),然后检查TouchPhase,而不是GetMouseButtonUp()。 And support multitouching going this way. 并以这种方式支持多点触控。

  void Update() {
    if (Input.GetTouch(0).phase == TouchPhase.ended) 
    {
        DoStuff();
    }
  }

Would have to use Touch events, there is complete example here: http://docs.unity3d.com/ScriptReference/Touch-phase.html 必须使用Touch事件,这里有完整的示例: http : //docs.unity3d.com/ScriptReference/Touch-phase.html

"TouchPhase.Ended" would be equal to OnMouseUp, but i dont think few OnMouseUp's would do any noticeable slowdowns to your game (you could check with profiler what if using most of the time and optimize those instead). “ TouchPhase.Ended”将等于OnMouseUp,但我认为很少有OnMouseUp会对您的游戏造成任何明显的影响(您可以使用事件探查器检查大部分时间的使用情况,并对其进行优化)。

Also you would have to then implement raycasting to check which object gets hit by the touch position. 另外,您还必须实施光线投射,以检查哪个物体被触摸位置击中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM