Advertisement
Staggart

Play particle effect on water trigger

Oct 19th, 2023 (edited)
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. //Note: The water object must have a BoxCollider attached to it with the "Is Trigger" box is checked.
  4. //The water object should also be on the "Water" layer.
  5. public class WaterEntryEffect : MonoBehaviour
  6. {
  7.     [Header("Leave this object unparented, so it can be positioned freely")]
  8.     // Effect should have simulation space set to "World" so it can be teleported freely
  9.     public ParticleSystem entryEffect;
  10.  
  11.     void OnTriggerEnter(Collider collider)
  12.     {
  13.         //Trigger if other object is on the "Water" layer
  14.         if (collider.gameObject.layer == 4)
  15.         {
  16.             // Position effect at current collision point and play
  17.             entryEffect.transform.position = this.transform.position;
  18.             entryEffect.Play();
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement