I have a script in which i shoot or “throw” boxes I can’t seem to figure out how to insert a code to play a throwing sound under my if (Input.GetButtonDown(“Fire2”)) {
section.
If anyone knows the proper way to trigger the audio segment please let me know. Heres my whole gun script.
using UnityEngine;
using System.Collections;
public class gun : MonoBehaviour {
public GameObject bulletPrefab;
public float bulletImpulse = 100f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("Fire2")) {
Camera cam = Camera.main;
GameObject bullet = (GameObject)Instantiate(bulletPrefab, cam.transform.position, cam.transform.rotation);
bullet.rigidbody.AddForce( cam.transform.forward * bulletImpulse, ForceMode.Impulse);
}
}
}
Read this page : http://answers.unity3d.com/page/newuser.html Please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window. Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
– AlucardJay