void Destroy() { Vector3 position = transform.position; var effect = PoolSystem.Instance.GetInstance <GameObject>(PrefabOnDestruction); effect.transform.position = position; effect.SetActive(true); int count = Physics.OverlapSphereNonAlloc(position, ReachRadius, s_SphereCastPool, 1 << 10); for (int i = 0; i < count; ++i) { Target t = s_SphereCastPool[i].GetComponent <Target>(); t.Got(damage); } gameObject.SetActive(false); m_Rigidbody.velocity = Vector3.zero; m_Rigidbody.angularVelocity = Vector3.zero; m_Owner.ReturnProjecticle(this); var source = WorldAudioPool.GetWorldSFXSource(); source.transform.position = position; source.pitch = Random.Range(0.8f, 1.1f); source.PlayOneShot(DestroyedSound); }
public void GetHit(float damage) { m_CurrentHealth -= damage; healthBar.value = m_CurrentHealth; if (HitPlayer != null) { HitPlayer.PlayRandom(); } if (m_CurrentHealth > 0) { gameObject.SendMessage("GetsProvoked"); return; } Vector3 position = transform.position; //the audiosource of the target will get destroyed, so we need to grab a world one and play the clip through it if (HitPlayer != null) { var source = WorldAudioPool.GetWorldSFXSource(); source.transform.position = position; source.pitch = HitPlayer.source.pitch; source.PlayOneShot(HitPlayer.GetRandomClip()); } if (DestroyedEffect != null) { var effect = PoolSystem.Instance.GetInstance <ParticleSystem>(DestroyedEffect); effect.time = 0.0f; effect.Play(); effect.transform.position = position; } m_Destroyed = true; gameObject.SetActive(false); GameSystem.Instance.TargetDestroyed(pointValue); }
public void PlayImpact(Vector3 position, Vector3 normal, Material material = null) { ImpactSetting setting = null; if (material == null || !m_SettingLookup.TryGetValue(material, out setting)) { setting = DefaultSettings; } var sys = PoolSystem.Instance.GetInstance <ParticleSystem>(setting.ParticlePrefab); sys.gameObject.transform.position = position; sys.gameObject.transform.forward = normal; sys.gameObject.SetActive(true); sys.Play(); var source = WorldAudioPool.GetWorldSFXSource(); source.transform.position = position; source.pitch = Random.Range(0.8f, 1.1f); source.PlayOneShot(setting.ImpactSound); }