在另一个脚本中使用脚本C#unity

时间:2019-03-28 15:55:02

标签: c# unity3d vuforia

我有一个问题,我与vuforia有一个统一的代码,在其中进行视频播放,我的问题是我想在另一个脚本中使用一个脚本,并且使用公共GameObject CamaraObject以便能够在另一个脚本中使用它但是在将其发送给呼叫时它无法识别我,您能告诉我我错了还是我遗漏了什么吗?,这里是我的代码:

'''C#MainManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;

public class MainManager : MonoBehaviour
{

public GameObject[] videoPlayer;


    public GameObject playButton;
    public GameObject stopButton;
    public GameObject nextButton;
    public GameObject prevButton;
    public GameObject muteButton;
    public GameObject soundButton;


    int CurrentPlayer = 0;
    // Start is called before the first frame update
    void Start()
    {
        DisableAll();
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void Play()
    {
        videoPlayer[CurrentPlayer].SetActive(true);
        videoPlayer[CurrentPlayer].GetComponent<VideoPlayer>().Play();
    }

    public void Pause()
    {
        videoPlayer[CurrentPlayer].GetComponent<VideoPlayer>().Pause();
    }

    public void Mute()
    {
        videoPlayer[CurrentPlayer].GetComponent<AudioSource>().mute=true;
    }

    public void Sound()
    {
        videoPlayer[CurrentPlayer].GetComponent<AudioSource>().mute = false;
    }

    public void Next()
    {
        CurrentPlayer++;
        Play();
    }

    public void Previous()
    {
        CurrentPlayer--;
        Play();
    }

    public void DisableAll()
    {
        foreach (var i in videoPlayer)
        {
            i.SetActive(false);
        }
    }
}

'''C#DefaultTrackableEventHandler.cs

using UnityEngine;
using Vuforia;

    protected TrackableBehaviour mTrackableBehaviour;
    protected TrackableBehaviour.Status m_PreviousStatus;
    protected TrackableBehaviour.Status m_NewStatus;
    #endregion // PROTECTED_MEMBER_VARIABLES
    public GameObject CamaraObject;


    protected virtual void OnTrackingFound()
    {
        var rendererComponents = GetComponentsInChildren<Renderer>(true);
        var colliderComponents = GetComponentsInChildren<Collider>(true);
        var canvasComponents = GetComponentsInChildren<Canvas>(true);

        // Enable rendering:
        foreach (var component in rendererComponents)
            component.enabled = true;

        // Enable colliders:
        foreach (var component in colliderComponents)
            component.enabled = true;

        // Enable canvas':
        foreach (var component in canvasComponents)
            component.enabled = true;

    CamaraObject.GetComponent<MainManager>().Play();
    }

我需要将此MainManager调用到CamaraObject.GetComponent。()。Play()行,但它说:缺少using指令或程序集引用

0 个答案:

没有答案