Can't play shoot sound
Okay so I have this shooting script which does work but now I wanted to implement some sound in it for the realism so here is the script
var Damage = 10;
var FireRate = 0.1F;
var NextFire = 0.0F;
var BulletRange = 200;
var Enemy : GameObject;
var GunFireSound : AudioClip;
function Update() {
if(Input.GetButton("Fire1") && Time.time > NextFire){
GetComponent.<AudioSource>().Clip = GunFireSound;
GetComponent.<AudioSource>().Play();
Rayshooting();
}
}
function Rayshooting() {
Debug.DrawRay(transform.position,transform.forward * BulletRange);
NextFire = Time.time + FireRate;
var hit : RaycastHit;
Physics.Raycast(transform.position,transform.forward,hit,BulletRange);
if (Physics.Raycast(transform.position,transform.forward,hit,BulletRange)&&hit.transform.gameObject == Enemy){
Debug.Log("Hit Enemy!");
hit.transform.SendMessage("DamageTaken", Damage, SendMessageOptions.DontRequireReceiver);
}
}
it doesn't give an error till I start up the game and click once then it gives me this error
MissingFieldException: UnityEngine.AudioSource.Clip Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.FindExtension (IEnumerable`1 candidates) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.Create (SetOrGet gos) Boo.Lang.Runtime.DynamicDispatching.PropertyDispatcherFactory.CreateSetter () Boo.Lang.Runtime.RuntimeServices.DoCreatePropSetDispatcher (System.Object target, System.Type type, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices.CreatePropSetDispatcher (System.Object target, System.String name, System.Object value) Boo.Lang.Runtime.RuntimeServices+c_AnonStorey19.<>m_F () Boo.Lang.Runtime.DynamicDispatching.DispatcherCache.Get (Boo.Lang.Runtime.DynamicDispatching.DispatcherKey key, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[] cacheKeyTypes, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[] args, System.String cacheKeyName, Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory) Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value) Raycast Shooting.Update () (at Assets/Yvalson Scripts/Raycast Shooting.js:12)
the strange thing is when I delete the line
GetComponent.().Clip = GunFireSound; and put a audiofile in the audiosource component manually it works without a problem
can someone explain to me what I'm doing wrong because I'm a beginner and this is bugging me
thanks
there is no Clip field, maybe try in lowercase? GetComponent.().clip
thanks man it worked now my code is working like a charm