“帧”真的是unity初学者的坑啊;稀里糊涂的以为懂了,结果在这个弹框问题上一直耗了一个月的样子都没有结果。幸运的是,今天从书上找到了答案。

private bool flag;//判断鼠标是否在物体上
private bool _isclick;//判断鼠标是否单击了

void Start () {
        flag = false;
        _isclick = false;

}

 public void mousein()   //这里通过给需要显示提示框的设备添加eventrigger组件,然后添加相应的OnPointerEnter函数来调                                     用mousein函数;注意,为3D物体添加触发器,还需要给camera添加PhysicsRayCaster组件,否则无                                      法检测鼠标的位置。
    {
        flag = true;
        Debug.Log(flag);
    }
    public void mouseout()
    {
        flag = false;
        _isclick = false;
        Debug.Log(flag);
    }
    void OnGUI()
    {
       
        if (flag)
        {
            if (Input.GetMouseButtonDown(0))//从这开始就涉及到帧的概念,OnGUI函数每帧都会调用,但是变量的值只要在某一帧的时候发生改变后,就会一直保持该值,不会受帧的影响。
            {
                _isclick = true;
            }
            if (_isclick)
            {
                GUILayout.BeginArea(new Rect(Input.mousePosition.x, Screen.height - Input.mousePosition.y, 300, 350));
                GUILayout.BeginHorizontal("Box");
                GUILayout.BeginVertical();
                GUILayout.Label("设备名称:");
                GUILayout.Label("设备型号:");
                GUILayout.Label("设备功能:");
                GUILayout.EndVertical();
                GUILayout.BeginVertical("Box", GUILayout.Width(200));
                GUILayout.TextField("123");
                GUILayout.TextField("123");
                GUILayout.TextField("123");
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                GUILayout.EndArea();
            }
        }
    }
}

最终效果图如下,单击物体显示提示框!

单击物体显示信息框

单击物体显示信息框

相关文章:

  • 2021-12-04
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-15
  • 2021-05-25
  • 2022-02-14
相关资源
相似解决方案