I’m very new to this, and am trying to get a sound when walking into a coin.
I was following this tutorial:
When running the code it gives me a CS0117 Error: ‘SoundManager’ does not contain a definition for ‘sdnMan’
Here is my ‘SoundManager.cs’ Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SoundManager : MonoBehaviour
{
public static SoundManager sndMan;
private AudioSource audioSrc;
private AudioClip[] coinSounds;
private int randomCoinSound;
// Start is called before the first frame update
void Start()
{
sndMan = this;
audioSrc = GetComponent<AudioSource>();
coinSounds = Resources.LoadAll<AudioClip>("CoinSounds");
}
public void PlayCoinSound()
{
randomCoinSound = Random.Range(0, 1);
audioSrc.PlayOneShot(coinSounds[randomCoinSound]);
}
}
And my Player Code:
using UnityEngine;
public class PlayerCtrl : MonoBehaviour
{
Rigidbody2D body;
float horizontal;
float vertical;
float moveLimiter = 0.7f;
public float runSpeed = 8.0f;
void Start()
{
body = GetComponent<Rigidbody2D>();
}
public Animator animator;
void Update()
{
// Gives a value between -1 and 1
horizontal = Input.GetAxisRaw("Horizontal"); // -1 is left
vertical = Input.GetAxisRaw("Vertical"); // -1 is down
animator.SetFloat("MoveHor", horizontal);
animator.SetFloat("MoveVer", vertical);
}
void FixedUpdate()
{
if (horizontal != 0 && vertical != 0) // Check for diagonal movement
{
// limit movement speed diagonally, so you move at 70% speed
horizontal *= moveLimiter;
vertical *= moveLimiter;
}
body.velocity = new Vector2(horizontal * runSpeed, vertical * runSpeed);
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Coins"))
{
Destroy(other.gameObject);
SoundManager.sdnMan.PlayCoinSound();
}
}
}
I’m not sure how to solve this. Appreciate it in advance