【问题标题】:Compile Error in VirtualButtonBehaviour syntaxVirtualButtonBehaviour 语法中的编译错误
【发布时间】:2018-12-31 16:40:05
【问题描述】:

我正在使用 Unity/Vuforia 引擎创建一个小应用程序,当我循环访问虚拟按钮时,我收到以下编译错误。

using System.Collections;    
using System.Collections.Generic;    
using UnityEngine;    
using Vuforia;

public class XYZScript : MonoBehaviour,IVirtualButtonEventHandler { 
    public GameObject xgo, ygo;
// Start is called before the first frame update
    void Start()
    {
        VirtualButtonBehaviour[] vrb = GetComponentInChildren<VirtualButtonBehaviour>();
        for(int i=0; i<vrb.Length; i++)
        {
            vrb[i].RegisterEventHandler(this);
        }
        xgo.SetActive(false);
        ygo.SetActive(false);        
    }

我收到了错误

VirtualButtonBehaviour[] vrb = GetComponentInChildren<VirtualButtonBehaviour>();

错误信息:

此行为将虚拟按钮与游戏对象相关联。使用 ImageTargetBehavior 中的功能在运行时创建和销毁虚拟按钮。

不能隐含隐蔽类型“Vuforia.VirtualButtonBehaviour”到 "Vuforia.VirtualButtonBehaviour[]"

【问题讨论】:

  • 第二个是错字,你可能想使用GetComponentsInChildren(注意s)。 (提示:您可能还想将 true 作为 orser 中的参数传递给它,以获取残疾儿童的组件。)我认为第一条错误消息是不言自明的......
  • @derHugo 非常感谢!效果很好!!

标签: c# unity3d vuforia vuforia-cloud-recognition


【解决方案1】:

VirtualButtonBehaviour[] vrb = GetComponentInChildren();

您必须更改 GetComponentInChildren 使用 GetComponentsInChildren

【讨论】:

  • 您从 cmets 复制了此答案。这只是一个错字。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 2022-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多