繁体   English   中英

如何将OnMouse事件转换为Android的Touch阶段?

[英]How to translate OnMouse events to Touch phases for Android?

我坚持使用一个相当简单的解决方案,将我的脚本翻译为在Android中使用Unity3d运行。 我有一个gameObject“ Cube”和一个用于旋转的js脚本。

另外,我在GUI.Texture上附加了脚本“ ClickButton.js”。 在Unity Player中一切正常,但是我想翻译此脚本以供Android设备中的触摸使用。 问题是,尽管我已阅读Unity文档,但我无法做到。

这是代码片段:

//This script is attached on a GUI.Texture acting as a button

var normalTexture : Texture2D;
var hoverTexture : Texture2D;

function Update(){
    for (var i = 0; i < Input.touchCount; ++i) {
        if (Input.GetTouch(i).phase == TouchPhase.Began)
            var rotate = Input.GetTouch(i);
            rotate == doRotate();
        }
    }
}

function OnMouseEnter(){
    guiTexture.texture = hoverTexture;
}

function OnMouseExit(){
    guiTexture.texture = normalTexture;
}

function OnMouseDown(){  
    var runScriptRotate : GameObject[] = GameObject.FindGameObjectsWithTag("Marker");    
    for(var doRotation : GameObject in runScriptRotate){    
        var scriptRT : doRotate = doRotation.GetComponent(doRotate);    
        if(scriptRT){
            // access the function "doRotation" on a script named "doRotate" on     gameObject "Cube"
            doRotate.doRotation();
        }    
    }      
}

有人可以友好地编辑此代码脚本,以便通过触摸使其在Android上运行吗? 谢谢大家!

您为什么不只复制OnMouseDown()的内容? 基本上,触摸与在Android设备上按下鼠标相同,不是吗?

if(Input.touchCount > 0){
    if(Input.GetTouch(0).phase == TouchPhase.Began){
        var runScriptRotate : GameObject[] = GameObject.FindGameObjectsWithTag("Marker");    
        for(var doRotation : GameObject in runScriptRotate){    
            var scriptRT : doRotate = doRotation.GetComponent(doRotate);    
            if(scriptRT){
                // access the function "doRotation" on a script named "doRotate" on gameObject "Cube"
                doRotate.doRotation();
            }    
        }     
    } 
}

暂无
暂无

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

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