Different Roll sounds ond different grounds c#

I try to make different sounds on different grounds:

		void OnCollisionStay( Collision collision_info )
	{
		 if( collision_info.gameObject.GetComponent<MeshCollider>()  gameObject.tag == "Wood" != null )
		{
			if ( ( !audio.isPlaying )  ( audio.clip != BallRollWoodSound ) )
			{
			_GameManager.GetComponent<GameManager>().BallRollWood();
			}
			audio.volume = rigidbody.velocity.magnitude * 0.2f;
			
			
			if ( ( !audio.isPlaying )  ( audio.clip != BallRollStoneSound )  gameObject.tag == "Concrete")
			{
			_GameManager.GetComponent<GameManager>().BallRollStone();
			}
			audio.volume = rigidbody.velocity.magnitude * 0.2f;
		}

        mIsGrounded = true;
	}
	
	
	
	void OnCollisionExit( Collision collision_info )
	{
		if( collision_info.gameObject.GetComponent<MeshCollider>() != null )
		{
		

           if( !audio.isPlaying )
            {
				_GameManager.GetComponent<GameManager>().BallHitGround();
           }
			
            audio.volume = rigidbody.velocity.magnitude * 0.2f;
        }
		
        mIsGrounded = false;
	}
	
	
	
	
	    void OnCollisionEnter( Collision collision_info )
		{
		 if( collision_info.gameObject.tag == "Wood"  GetComponent<MeshCollider>()  != null )
		{
			if ( ( !audio.isPlaying )  ( audio.clip != BallRollWoodSound ) )
			{
			_GameManager.GetComponent<GameManager>().BallRollWood();
			}
			audio.volume = rigidbody.velocity.magnitude * 0.2f;
			
			{
				if( collision_info.gameObject.tag == "Concrete"  GetComponent<MeshCollider>()  != null )
			if ( ( !audio.isPlaying )  ( audio.clip != BallRollStoneSound )  gameObject.tag == "Concrete")
			{
			_GameManager.GetComponent<GameManager>().BallRollStone();
			}
			audio.volume = rigidbody.velocity.magnitude * 0.2f;
		}
		}
        mIsGrounded = true;
	}

But i always get only the BallRollWoodSound

The Objects have the tags “wood” and “concrete” placed right:

Any ideas for me?

if( collision_info.gameObject.GetComponent<MeshCollider>()  gameObject.tag == "Wood" != null )

I’m surprised that compiles. Are you seeing any warnings or errors in your console?

Then, inside that, your inner checks, see my added comments

if ( ( !audio.isPlaying )  ( audio.clip != BallRollWoodSound ) )
{
	_GameManager.GetComponent<GameManager>().BallRollWood();
}
audio.volume = rigidbody.velocity.magnitude * 0.2f;

if ( ( !audio.isPlaying )  ( audio.clip != BallRollStoneSound )  gameObject.tag == "Concrete")
{
	_GameManager.GetComponent<GameManager>().BallRollStone()
}
audio.volume = rigidbody.velocity.magnitude * 0.2f;

On the first check: is audio.clip ever going to equal BallRollWoodSound?

On the second check: if GameManager.BallRollWood() plays a sound on this object, will audio.isPlaying ever be false?

yepp, my code is really weird, But i have no errors in the console.

I also think there must be an easier way to implent different sound for different grounds?

This here:

void OnControllerColliderHit ( ControllerColliderHit hit) {

if (controller.isGrounded  controller.velocity.magnitude < 7  controller.velocity.magnitude > 5  hit.gameObject.tag == "Untagged"  step == true ) {
    RollOnConcrete();
} else if (controller.isGrounded  controller.velocity.magnitude > 8  hit.gameObject.tag == "Concrete"  step == true || controller.isGrounded  controller.velocity.magnitude > 8  hit.gameObject.tag == "Untagged"  step == true) {
    RollOnConcrete();

But i am not sure…

Ok i am here:

using UnityEngine; 
using System.Collections;

public class PlayerControl : MonoBehaviour {


	private GameObject moveJoy;
	private GameObject _GameManager;
	public Vector3 movement;
	public float moveSpeed = 6.0f;
	public float jumpSpeed = 5.0f;
	public float drag = 3;
	private bool canJump = false;
	public float soundFadeSpeed = 2;
	public AudioClip BallRollWoodSound;
	public AudioClip BallRollStoneSound;
	public AudioClip BallHitGroundSound;
	public CharacterController controller;
        private bool step = true; 
        float audioStepLengthWalk = 0.45f; 
        float audioStepLengthRun = 0.25f;
	
	
	
	
		void Start()
	{
		moveJoy = GameObject.Find("LeftJoystick");
		_GameManager = GameObject.Find("_GameManager");

	}
	
	void Update () 
	{	
		Vector3 forward = Camera.main.transform.TransformDirection(Vector3.forward);
		forward.y = 0;
		forward = forward.normalized;

		
		Vector3 forwardForce = new Vector3();
		if (Application.platform == RuntimePlatform.Android) 
		{
			float tmpSpeed = moveJoy.GetComponent<Joystick>().position.y;
			forwardForce = forward * tmpSpeed * 1f * moveSpeed;
		}
		else
		{
			forwardForce = forward * Input.GetAxis("Vertical") * moveSpeed;

			
		}
		rigidbody.AddForce(forwardForce);
		
		
		Vector3 right= Camera.main.transform.TransformDirection(Vector3.right);
		right.y = 0;
		right = right.normalized;
		
		Vector3 rightForce = new Vector3();
		if (Application.platform == RuntimePlatform.Android) 
		{
			float tmpSpeed = moveJoy.GetComponent<Joystick>().position.x;
			rightForce = right * tmpSpeed * 0.8f * moveSpeed;
		}
		else
		{
			rightForce= right * Input.GetAxis("Horizontal") * moveSpeed;
		}		
		rigidbody.AddForce(rightForce);

		
		if (canJump  Input.GetKeyDown(KeyCode.Space))
		{
			rigidbody.AddForce(Vector3.up * jumpSpeed * 100);
			canJump = false;
			_GameManager.GetComponent<GameManager>().BallJump();
		}
		
		audio.volume = rigidbody.velocity.magnitude * 0.2f;
		}
	

	
	void OnTriggerEnter(Collider other) 
	{
		if (other.tag == "Destroy")
		{
			_GameManager.GetComponent<GameManager>().Death();
			Destroy(gameObject);
		}
		else if (other.tag == "Coin")
		{
			Destroy(other.gameObject);
			_GameManager.GetComponent<GameManager>().FoundCoin();
		}
		else if (other.tag == "SpeedBooster")
		{
			movement = new Vector3(0,0,0);
			_GameManager.GetComponent<GameManager>().SpeedBooster();
		}
		else if (other.tag == "JumpBooster")
		{
			movement = new Vector3(0,0,0);
			_GameManager.GetComponent<GameManager>().JumpBooster();
		}
		else if (other.tag == "Teleporter")
		{
			movement = new Vector3(0,0,0);
			_GameManager.GetComponent<GameManager>().Teleporter();
		}
    }
	
	

void OnControllerColliderHit ( ControllerColliderHit hit) {

if (controller.isGrounded  controller.velocity.magnitude < 7  controller.velocity.magnitude > 5  hit.gameObject.tag == "Untagged"  step == true ) {
    WalkOnConcrete();
} else if (controller.isGrounded  controller.velocity.magnitude > 8  hit.gameObject.tag == "Concrete"  step == true || controller.isGrounded  controller.velocity.magnitude > 8  hit.gameObject.tag == "Untagged"  step == true) {
    RunOnConcrete();
} else if (controller.isGrounded  controller.velocity.magnitude < 7  controller.velocity.magnitude > 5  hit.gameObject.tag == "Wood"  step == true) {
    WalkOnWood();
} 
	
}

IEnumerator WaitForPlayerControl(float stepsLength) { step = false; yield return new WaitForSeconds(stepsLength); step = true; }

/////////////////////////////////// CONCRETE //////////////////////////////////////// 
void WalkOnConcrete() {

audio.clip = BallRollStoneSound;
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForPlayerControl(audioStepLengthWalk));
}

void RunOnConcrete() {

audio.clip = BallRollStoneSound;
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForPlayerControl(audioStepLengthWalk));
}

////////////////////////////////// WOOD ///////////////////////////////////////////// 
void WalkOnWood() {

audio.clip = BallRollWoodSound;
audio.volume = 0.1f;
audio.Play();
StartCoroutine(WaitForPlayerControl(audioStepLengthWalk));
}

void RunOnWood() {

audio.clip = BallRollWoodSound;
audio.volume = 0.3f;
audio.Play();
StartCoroutine(WaitForPlayerControl(audioStepLengthRun));
}

}

But again… i have only hear my wood rolling sound
I stuck here
any help would be nice :slight_smile:

I did not understand that:

public float height;
	void Start()
	{
		moveJoy = GameObject.Find("LeftJoystick");
		_GameManager = GameObject.Find("_GameManager");
		height = collider.bounds.extents.y + 0.2f;
	}
		void OnCollisionStay( Collision collision )
	{

		{
			if ( ( !audio.isPlaying )  ( audio.clip != BallRollWoodSound )  (rigidbody.velocity.magnitude > 1.0f)  (Physics.Raycast(transform.position, Vector3.down, height) ))
			{
				
                audio.clip = BallRollWoodSound;
				audio.loop = true;
				audio.Play();
			}
			audio.volume = rigidbody.velocity.magnitude * 0.2f;
		}


	}

when the ball is in the air it should play no sound…, but the sound is playing also in air, but should stop.

help please. Height do not change in inspector window :frowning: