- Home /
Question by
mrzeapple · Jan 14, 2014 at 01:24 AM ·
clipping planeignore collisionsaudio clippingcollision event
On Collision sound clip change
I'm trying to make is so if someone went on land the sound of one walking on it will play, and if you go into the ocean it will sound like you are swimming.
using UnityEngine;
using System.Collections;
public class audio : MonoBehaviour {
// Use this for initialization
void Start () {
}
public AudioClip land;
public AudioClip swim;
// Update is called once per frame
void Update () {
}
void OnCollisitionEnter(Collision collision){
if(collision.gameObject.name == "island"){
Debug.Log("land");
if (Input.GetKeyDown(KeyCode.W)){
audio.clip = land;
audio.Play();
}
if(Input.GetKeyUp(KeyCode.W)){
audio.Stop();
}
}
if(collision.gameObject.name == "water"){
if (Input.GetKeyDown(KeyCode.W)){
audio.clip = swim;
audio.Play();
}
if(Input.GetKeyUp(KeyCode.W)){
audio.Stop();
}
}
}
}
Comment
Answer by getyour411 · Jan 14, 2014 at 01:43 AM
check spelling of OnCollisionEnter vs OnCollisitionEnter