Sound when object is touched

I am newbie at scripting in Unity, i know some C++ but that’s all. I have specific objects that i want, when touched, to make sound that i have. I also need that, when i touched one object and it made one sound, another sound is attached to a certain object. Example: I went to the car and it made “roar” sound, now if i come to the tree it will say “meow”, but if i came to the tree first it wouldn’t make the sound.
@UnrealSoftware

I am really new at this, i don’t understand it, can you be more detailed ?

Hello @Sima211

sorry for the late reply…

I deleted my previous answer because I think the answer is not proper relevant to your question

  1. Are you able to make the sound when you came near the car or tree ?
  2. you can set the bool/flag to true when you play the car sound. Now check if the bool is true only then the tree sound ( meow ) should be played

please use switch case if you have number of elements to check.
But I also think this is not the best approach because if you have to handle number of elements like this then this logic is not correct from my point of view. Rest the code or logic may be changed as per demand of the gameplay or scenario.

    AudioSource sfxAudioSource;
	AudioClip[] sfxAudioClips; //0 for car & 1 for Meow
	bool flag;

	void OnCollisionEnter( Collision collision){
		if ( collision.transform.tag == "Car"){
			// play sound here 
			sfxAudioSource.PlayOneShot(sfxAudioClips[0]);
			flag = true;
		}

		if ( collision.transform.tag == "tree" && flag){
			sfxAudioSource.PlayOneShot(sfxAudioClips[1]);
		}

	}