Answer the question
In order to leave comments, you need to log in
`
Error CS0120: An object reference is required to access non-static member `UnityEngine.AudioSource.Play()', how to solve it?
Here is the whole code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickUpCoin : MonoBehaviour {
public static AudioSource PickUpCoins;
public int Coins;
void Start () {
PickUpCoins = GetComponent <AudioSource> ();
}
void OnTriggerEnter(Collider other) {
if (other.tag == "Coin")
{
Coins++;
UnityEngine.AudioSource.Play ();
Destroy(other.gameObject);
}
}
void OnGUI()
{
GUILayout.Label("Coins = " + Coins);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question