Hi there guys,
So basically here is my front movement script, but I am unsure of how to write up a script that would make a sound work for the push that is used in this script. I have already imported the sound to unity and made a variable of it accordingly…(var pushSound : AudioClip;) how do I proceed further to make the sound work when I push the box?
here is the coding so far…
if (Input.GetKeyDown(KeyCode.UpArrow)) {
if (Physics.Raycast (transform.position, fwd, hit,1)) {
print ("There is something in front of the object!");
if(hit.collider.gameObject.tag!="Push"
)
{
if (hit.collider.gameObject.tag == "endGame"){
Application.LoadLevel(0);
}else{
transform.position += Vector3.up;
//animation.CrossFade("DefaultAnim", 0.2);
}
}
else{
print ("Push!");
var pushHit1:RaycastHit;
if (!Physics.Raycast (hit.collider.gameObject.transform.position, fwd, pushHit1,1)) {
hit.collider.gameObject.transform.position += Vector3.forward;
transform.position += Vector3.forward;
audio.PlayOneShot(pushSound, 0.7);
}
}
}else{
Debug.Log("nothing in front");