private void Awake() { if (inst == this) { return; } if (inst != null) { bool keepOther = conflictResolution == ConflictResolution.DestroyNewer || (id == inst.id && conflictResolution == ConflictResolution.DestroyNewerIfSameId); if (keepOther) { gameObject.SetActive(false); return; } else { inst.Stop(); Spawnable.Despawn(inst.gameObject, inst.GetComponent <AudioFade>().fadeDuration); } } audioSources = GetComponentsInChildren <AudioSource>(); currentIndex = shuffle ? UnityEngine.Random.Range(0, audioSources.Length) : 0; inst = this; if (persistThroughLoad) { DontDestroyOnLoad(gameObject); } }
private void OnParticleSystemStopped() { if (_despawnOnDone && _spawnable.IsSpawned) { Spawnable.Despawn(_spawnable); } }
/// <summary> /// A more versatile version of AudioSource.PlayClipAtPoint. /// </summary> /// <param name="clip">The clip to play.</param> /// <param name="point">The point at which to play.</param> /// <param name="volume">The volume to play at.</param> /// <param name="spatial">Spatial blend (0 = 2D, 1 = 3D).</param> /// <param name="pitch">The pitch to play at.</param> /// <param name="loop">Whether to loop the sound.</param> /// <param name="output">Output mixer group.</param> /// <param name="attach">Transform to attach the spawned AudioSource to.</param> /// <returns>The spawned AudioSource.</returns> public static AudioSource PlayClipAtPoint(AudioClip clip, Vector3 point, float volume = 1, float spatial = 1, float pitch = 1, bool loop = false, AudioMixerGroup output = null, Transform attach = null) { if (clip == null) { return(null); } GameObject obj = new GameObject(); obj.name = "One shot audio (SBR)"; obj.transform.parent = attach; obj.transform.position = point; var src = obj.AddComponent <AudioSource>(); src.clip = clip; src.loop = loop; src.spatialBlend = spatial; src.volume = volume; src.pitch = pitch; src.outputAudioMixerGroup = output; src.Play(); if (!loop) { Spawnable.Despawn(obj, clip.length); } return(src); }
private void Update() { timeToLive -= Time.deltaTime; if (timeToLive <= 0) { if (spawnOnDeath) { Spawnable.Spawn(spawnOnDeath, transform.position, transform.rotation); } Spawnable.Despawn(gameObject); } }
public override void Fire(Vector3 direction, bool align = true) { base.Fire(direction, align); RaycastHit hit; if (Physics.Raycast(transform.position, direction, out hit, range, hitMask, triggerInteraction)) { OnHitCollider(hit.collider, hit.point); } else { Spawnable.Despawn(gameObject, linger); } }
protected virtual void OnHitObject(Transform col, Vector3 position) { Vector3 impact = velocity * impactForce; col.Damage(new PointDamage(damage * damageMultiplier, position, velocity.normalized, velocity.magnitude * impactForce)); if (impactForce > 0) { var rb = col.GetComponentInParent <Rigidbody>(); if (rb) { rb.AddForce(impact, ForceMode.Impulse); } var rb2d = col.GetComponentInParent <Rigidbody2D>(); if (rb2d) { rb2d.AddForce(impact, ForceMode2D.Impulse); } } HitObject?.Invoke(col.gameObject, position); if (stopOnHit) { velocity = Vector3.zero; } if (destroyOnHit) { Spawnable.Despawn(gameObject, linger); fired = false; } if (impactSound) { impactSound.PlayAtPoint(transform.position); } if (impactPrefab) { Spawnable.Spawn(impactPrefab, position, transform.rotation, parentImpactObject ? col : null, true); } }
public override void Fire(Vector3 direction, bool align = true) { base.Fire(direction, align); RaycastHit2D hit; bool trig = Physics2D.queriesHitTriggers; Physics2D.queriesHitTriggers = hitsTriggers; if (hit = Physics2D.Raycast(transform.position, direction, range, hitMask)) { OnHitCollider2D(hit.collider, hit.point); } else { Spawnable.Despawn(gameObject, linger); } Physics2D.queriesHitTriggers = trig; }