I got some sound effects but i only know how they are in game not on a character like if you are shooting.
Here is the code for my player, can you fix it and send it back:
//Moving around
var speed = 3.0;
//Shooting
var bullitPrefab : Transform;
//Dying
static var dead = false;
//function OnControllerHit(hit: ControllerColliderHit)
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//substract life here
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enemyprojectile")
{
gothit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Fire1"))
{
var bullit = Instantiate(bullitPrefab,
transform.Find("spawnpoint").transform.position,
Quaternion.identity);
bullit.tag ="wormProjectile";
bullit.rigidbody.AddForce(transform.forward * 2000);
}
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0, 1, 0);
gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
dead = false;
}
}
@script RequireComponent(CharacterController)
Acutally pretty simple. First, make sure you have an audio clip and an audio source. Then play it one time each time you press fire1
See the red code.
//Moving around
var speed = 3.0;
//Shooting
var bullitPrefab : Transform;
//Dying
static var dead = false;
[COLOR="red"]// sound
var fireSound : AudioClip;[/COLOR]
//function OnControllerHit(hit: ControllerColliderHit)
function OnTriggerEnter(hit : Collider)
{
if(hit.gameObject.tag == "fallout")
{
dead = true;
//substract life here
HealthControl.LIVES -= 1;
}
if(hit.gameObject.tag == "enemyprojectile")
{
gothit = true;
HealthControl.HITS += 1;
Destroy(hit.gameObject);
}
}
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
if(Input.GetButtonDown("Fire1"))
{
var bullit = Instantiate(bullitPrefab,
transform.Find("spawnpoint").transform.position,
Quaternion.identity);
bullit.tag ="wormProjectile";
bullit.rigidbody.AddForce(transform.forward * 2000);
[COLOR="red"]if(fireSound)audioSource.PlayOneShot(fireSound);[/COLOR]
}
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(0, 1, 0);
gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
dead = false;
}
}
@script RequireComponent(CharacterController)
[COLOR="red"]@script RequireComponent(AudioSource)[/COLOR]