Calling function from another class in another script

Hello! I’m new here, so forgive me if I didn’t use the correct format to post my code. Anyways, I want to call the “something” function in a separate script (goldbuttonpush) when the Y button is hit. The whole point behind this, is that I’m trying to deactivate the audio when the button is pressed. This audio starts up in the beginning of the game and continues all the way through, but I want it to end specifically once the button is pushed.

The code I posted doesn’t work unfortunately and I don’t understand why. For some reason, the button no longer even changes position when I add “other.something”, but it works just fine when I don’t add that. So I’m really confused lol.


using UnityEngine;
using System.Collections;

public class Audio1 : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	public void something () {
		audio.enabled = false;
	}
}

using UnityEngine;
using System.Collections;

public class goldbuttonpush : MonoBehaviour {
	public Audio1 other;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () { 
		if (Input.GetKeyDown(KeyCode.Y)) {
		other.something();	
		audio.Play();
		transform.position = new Vector3(1856.377f,2.293061f,1540.691f);
}
}
}

Your code looks valid, if a bit messy.

You probably need to link your script through the inspector. This is a common stumbling block for people new to unity.

Whatever game object has goldbuttonpush on it you need to drag the object with the Audio1 script on it into the slot in the inspector for Audio1 objects.

Imgur

So you’re dragging some object in your heirarchy into your inspector (which I boxed in red in that example screenshot).