簡體   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