0

我正在使用 Vuforia 开发 Unity。

我有虚拟按钮,我需要像键盘上的向上/向下箭头一样移动不在其图像目标中的对象,所以我正在寻找基础知识。

我的课是这样开始的:

public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
...
}

我需要在其中添加什么才能使其像向上按钮一样?

如果没有这些虚拟按钮,我的脚本会像这样移动对象:

void FixedUpdate(){
        float moveHortizonal = Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHortizonal, 0, moveVertical);

        rigidbody.AddForce (movement * speed);
    }
4

1 回答 1

1

想出了如何去做,这里有一个关于我的发现的小教程

首先,您从注册按钮开始:

void Start () {
        VirtualButtonBehaviour[] vbs = transform.GetComponentsInChildren<VirtualButtonBehaviour> ();

        for (int i=0; i < vbs.Length; ++i) {
            vbs[i].RegisterEventHandler(this);
        }

现在你继续,从按钮的功能开始

   public void OnButtonPressed(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

同样,如果您希望按钮在发布时执行某些操作:

   public void OnButtonReleased(VirtualButtonAbstractBehaviour vb){
    //specify which button you want to function by using the if statement
    if(vb.name=="ButtonName") { callButtonfunction();}
    }

如果你想让你的按钮控制一个游戏对象,那么继续在类中将游戏对象声明为一个公共变量,以便它可以在检查器中访问并相应地分配。

public GameObject human;

GameObject变量类型在哪里,human是我们用来参考的变量名

就这么简单。

Vuforia 日志的记录非常糟糕,因此您几乎永远无法从那里得到答案,所以我希望这会有所帮助。

于 2015-03-13T02:52:47.590 回答