public virtual void Fire(GameObject ship, Vector3 position, Vector3 direction) { var bullet = BulletPool.get().Take(this); var bulletComponent = bullet.GetComponent <FlyItem>(); if (null == bulletComponent) { return; } m_ShotErrorValue = Math.Min(m_ShotErrorValueMax, m_ShotErrorValue + m_ShotErrorValueIncrement); float errorValueHalf = m_ShotErrorValue / 2; float offsetValue = UnityEngine.Random.Range(-errorValueHalf, errorValueHalf); bulletComponent.clean(); bulletComponent.FlyDirection = Quaternion.AngleAxis(offsetValue, Vector3.forward) * direction; bulletComponent.transform.position = position; bulletComponent.FlyVelocity = BulletFlyVelocity; bulletComponent.Life = ShutRange; bulletComponent.WeaponClassName = GetType().Name; bulletComponent.WeaponType = m_Type; bulletComponent.Ship = ship; bulletComponent.Damage = Damage; bulletComponent.m_Weapon = this; var soundObj = SoundsPool.get().Take(m_FireAudioResouce); if (null == soundObj) { return; } soundObj.transform.position = position; AudioSource soundCom = soundObj.GetComponent <AudioSource>(); if (null == soundCom) { return; } Ship shipCom = ship.GetComponent <Ship>(); if (InfluenceMG.INFLUENCE_PLAYER == shipCom.m_ShipStruct.Influence) { soundCom.priority = 10; } else { soundCom.priority = 100; } soundCom.Play(); }
// Update is called once per frame void Update() { AudioSource audio = GetComponent <AudioSource>(); if (null == audio) { return; } if (audio.isPlaying) { IsPlaying = true; return; } if (IsPlaying) { IsPlaying = false; SoundsPool.get().Recycle(gameObject); } }
private void Awake() { BulletPool.get().init(); SoundsPool.get().init(); InfluenceMG.get().init(); }