mikdog

ParticleFlipper for Adventure Creator

Feb 13th, 2026
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class ParticleFlipper : MonoBehaviour
  4. {
  5. // Assign the character's sprite object (the one AC flips) here
  6. public Transform spriteToFollow;
  7.  
  8. private Vector3 defaultPosition;
  9. private Vector3 defaultScale;
  10.  
  11. void Awake()
  12. {
  13. defaultPosition = transform.localPosition;
  14. defaultScale = transform.localScale;
  15. }
  16.  
  17. void LateUpdate()
  18. {
  19. if (spriteToFollow == null) return;
  20.  
  21. // Check if the parent sprite is flipped (Scale X is negative)
  22. bool isFlipped = spriteToFollow.localScale.x < 0;
  23.  
  24. // Invert the local X position if flipped
  25. float newX = isFlipped ? -defaultPosition.x : defaultPosition.x;
  26. transform.localPosition = new Vector3(newX, defaultPosition.y, defaultPosition.z);
  27.  
  28. // Optional: Flip the particle rotation/angle if needed
  29. // transform.localScale = new Vector3(isFlipped ? -defaultScale.x : defaultScale.x, defaultScale.y, defaultScale.z);
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment