public void reload() { //reload noise WeaponSounds.PlaySound("reload"); coroutine = waittoShoot(0.5f); StartCoroutine(coroutine); }
void EquipWeapon(PlayerWeapon _weapon) { currentWeapon = _weapon; GameObject _weaponIns = Instantiate(_weapon.graphics, weaponHolder.position, weaponHolder.rotation); _weaponIns.transform.SetParent(weaponHolder, false); currentGraphics = _weaponIns.GetComponent <WeaponGraphics>(); if (currentGraphics == null) { Debug.LogError("No WeaponGraphics component on the weapon object: " + _weaponIns.name); } currentSounds = _weaponIns.GetComponent <WeaponSounds>(); if (currentSounds == null) { Debug.LogError("No WeaponSounds component on the weapon object: " + _weaponIns.name); } if (isLocalPlayer) { Util.SetLayerRecursively(_weaponIns, LayerMask.NameToLayer(weaponLayerName)); } }
public void Shoot() { shootable = false; WeaponSounds.PlaySound("snipershot"); RaycastHit hitInfo; //info of raycast if (Physics.Raycast(ray, out hitInfo, range)) { Debug.DrawLine(ray.origin, hitInfo.point, Color.red); Debug.Log(hitInfo.collider.name); // console log infor for development Health target = hitInfo.transform.GetComponent <Health>(); // finding health script on the hit target if (target != null) //if there was a health script attached to the object { target.takeDamage(damage); //run take damage on ray cast hit object } } else { //couldnt find objects with weaponry Debug.DrawLine(ray.origin, ray.direction * range, Color.green); Debug.Log("false"); } coroutine = waitandReload(0.5f); StartCoroutine(coroutine); }
public AudioSource PlayEnemyGun(WeaponSounds weapon, int index, GameObject target, bool seperateObject) { string name = weapon.ToString() + index; if (seperateObject == true) { GameObject _targetAudio = new GameObject(target.name + " audio source. Playing - " + name); _targetAudio.transform.parent = target.transform; _targetAudio.transform.position = target.transform.position; _targetAudio.tag = "WeaponAudio"; target = _targetAudio; } Sound s = null; if (weapon.ToString() == "Short") { name = "ShortWeapon" + (index + 1).ToString(); s = Array.Find(shortWeaponSounds, sound => sound.name == name); } else if (weapon.ToString() == "Medium") { name = "MediumWeapon" + (index + 1).ToString(); s = Array.Find(mediumWeaponSounds, sound => sound.name == name); } else if (weapon.ToString() == "Long") { name = "LongWeapon" + (index + 1).ToString(); s = Array.Find(longWeaponSounds, sound => sound.name == name); } AudioSource _source = target.AddComponent <AudioSource>(); _source.clip = s.clip; _source.volume = s.volume - 0.7f; _source.pitch = s.pitch; _source.loop = s.loop; _source.priority = s.priority - 5; _source.rolloffMode = AudioRolloffMode.Linear; _source.minDistance = 30; _source.maxDistance = 1000; _source.spatialBlend = 1f; _source.outputAudioMixerGroup = fx; return(_source); }
public override void Initialize(WeaponData data) { base.Initialize(data); sounds = data.sounds; }