Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface 在UnityScript中,为什么GUI不能在碰撞器中被调用?_User Interface_Touch_Unityscript - Fatal编程技术网

User interface 在UnityScript中,为什么GUI不能在碰撞器中被调用?

User interface 在UnityScript中,为什么GUI不能在碰撞器中被调用?,user-interface,touch,unityscript,User Interface,Touch,Unityscript,我试图在用户触摸精灵时打印文本,但是,即使我在构建和运行代码时没有出错,代码拒绝打印文本,我也无法理解我做错了什么。请帮助我理解为什么它不打印。 当我触摸精灵时,它会打印调试文本,但不会打印带有total的GUI文本 代码如下: #pragma strict function Start () { OnGUI(); } function OnGUI(){ //var total = 0; //GUI.Label( myRect, total.ToString() ); // D

我试图在用户触摸精灵时打印文本,但是,即使我在构建和运行代码时没有出错,代码拒绝打印文本,我也无法理解我做错了什么。请帮助我理解为什么它不打印。 当我触摸精灵时,它会打印调试文本,但不会打印带有total的GUI文本

代码如下:

#pragma strict

function Start () {


OnGUI();
}

function OnGUI(){
//var total = 0;

    //GUI.Label( myRect, total.ToString() ); // Displays "10".
    //GUI.Label( myRect, "" + bullets ); // Displays "10".
   // GUI.Label(Rect(0,0,Screen.width,Screen.height),"Total:"+total);
}
//function Update () {

//}
var platform : RuntimePlatform = Application.platform;

function Update(){

    if(platform == RuntimePlatform.Android || platform == RuntimePlatform.IPhonePlayer){
       if(Input.touchCount > 0) {
         if(Input.GetTouch(0).phase == TouchPhase.Began){
          checkTouch(Input.GetTouch(0).position);
         }
       }
    }else if(platform == RuntimePlatform.WindowsEditor){
       if(Input.GetMouseButtonDown(0)) {
         checkTouch(Input.mousePosition);
       }
    }
}

function checkTouch(pos){
var total = 0;

    var wp : Vector3 = Camera.main.ScreenToWorldPoint(pos);
    var touchPos : Vector2 = new Vector2(wp.x, wp.y);
    var hit = Physics2D.OverlapPoint(touchPos);

    if(hit){
    GUI.Label(Rect(0,0,Screen.width,Screen.height),"Total:");
       Debug.Log(hit.transform.gameObject.name);
       hit.transform.gameObject.SendMessage('Clicked',0,SendMessageOptions.DontRequireReceiver);


      //total = total +1;
    }
}

不能将gui项置于OnGUI方法之外。您需要设置一个布尔值来打开标签。 沿着这条线的东西

OnGUI(){
if(labelbool)
    GUI.Label ....
}

check(){
labelbool = true;
}

你的精灵上有对撞机吗?