Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class ParticleFlipper : MonoBehaviour
- {
- // Assign the character's sprite object (the one AC flips) here
- public Transform spriteToFollow;
- private Vector3 defaultPosition;
- private Vector3 defaultScale;
- void Awake()
- {
- defaultPosition = transform.localPosition;
- defaultScale = transform.localScale;
- }
- void LateUpdate()
- {
- if (spriteToFollow == null) return;
- // Check if the parent sprite is flipped (Scale X is negative)
- bool isFlipped = spriteToFollow.localScale.x < 0;
- // Invert the local X position if flipped
- float newX = isFlipped ? -defaultPosition.x : defaultPosition.x;
- transform.localPosition = new Vector3(newX, defaultPosition.y, defaultPosition.z);
- // Optional: Flip the particle rotation/angle if needed
- // transform.localScale = new Vector3(isFlipped ? -defaultScale.x : defaultScale.x, defaultScale.y, defaultScale.z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment