walkSound is a field but a type was expected

Hey guys,

I’m new to C# so I don’t know how to fix a problem. I scripted something into my CharacterController, which plays a sound when a specific button is pressed, but i get the Error CharacterController.jumpSound' is a field’ but a `type’ was expected.

This is the important part of the code:

using UnityEngine;
using System.Collections;

public class CharacterController : MonoBehaviour {
//soundfx
public AudioClip[] walkSound;
void Update ()
{
if(Input.GetKeyDown(KeyCode.A))
{
PlayWalkSound();
}
}
void PlayWalkSound()
{
audio.clip = walkSound[];
audio.Play ();
}
}

What do I need to do so it will work?

  • audio.clip = walkSound[ ]; // You’ve not set the index you want to use
audio.clip = walkSound[0]; //this will play the first audiclip in the array
1 Like

fortunately i already figured it out. Thanks for you help :slight_smile: