so my character will run into every object and make a sound(a swap sound) . But there’s this specific object I want to make a different sound (laser sound) after I collide with it and after I collide with it I want it to also disappear.
So what happens so far is I collide with my object and it disappears with no sound. But I get this warning
Can not play a disabled audio source
UnityEngine.AudioSource:Play()
FPSController:OnTriggerEnter(Collider) (at Assets/Scripts/FPSController.js:28)
I attached my code to the object I want to make a sound and to my character
here it is
var Laser : AudioClip;
function SpeedUpPlayer()
{
Debug.Log("If the code would've been here, the player would have sped up.");
}
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player")
{
var fpscontrol : FPSController = GetComponent(FPSController);
fpscontrol.SpeedUpPlayer();
DestroyObject (gameObject);
audioClip = Laser;
audio.Play();
}
}
PLEASE HELP
You are assigning the audio clip to a variable, but not actually setting it on the audio component. Also you are destroying i assume the gameobject before playing the audio.
var Laser : AudioClip;
function SpeedUpPlayer()
{
Debug.Log("If the code would've been here, the player would have sped up.");
}
function OnTriggerEnter(other : Collider)
{
if (other.tag == "Player")
{
var fpscontrol : FPSController = GetComponent(FPSController);
fpscontrol.SpeedUpPlayer();
audio.clip = Laser;
audio.Play();
Destroy(gameObject,Laser.length);
}
I would suggest really looking at some unity tutorials, because it looks like you have no clue how to do some very simple stuff.
Yes you are correct I don’t know even the simple stuff, but I feel it would take too long to understand the basics during my last semester of my College years. I’m trying to at least pass and get my advanced diploma and move on to art stuff not programming. I’m not even sure why they put programming in my program when the whole program is a art based program.