0
votes

I've looked up similar questions and responses and still have not been able to get this to work.

LessonRightButton.js

//#pragma strict
public var audio1 : AudioPlayback;

function OnClick(){
        var findAudioSource = GameObject.Find("AudioPlaybackButton");
        var audio1:AudioPlayback = findAudioSource.GetComponent(AudioPlayback);
        audio1.woo(); //  THIS IS LINE 50 IN THE ERROR
}

AudioPlayback.js

//#pragma strict

function woo(){
    Debug.Log("wooooooooooooooo");
}

I get this error:

NullReferenceException: Object reference not set to an instance of an object LessonRightButton.OnClick () (at Assets/Scripts/LessonRightButton.js:50)

I'm trying to call the woo function from a different script. These scripts are shortened for the purpose of ease of reading. Please advise.

1

1 Answers

0
votes

you have no AudioPlayback attached on that AudioPlaybackButton object.

Either add one manually or by code:

function OnClick(){
        var findAudioSource = GameObject.Find("AudioPlaybackButton");
        var audio1:AudioPlayback = findAudioSource.GetComponent(AudioPlayback);
        if(audio1 == null){
            audio1 = findAudioSource.AddComponent(AudioPlayback);
        }
        audio1.woo();    
}