Untitled
unknown
csharp
a year ago
889 B
11
Indexable
using UnityEngine;
public class EnemyFlip : MonoBehaviour
{
private float previousXPosition;
void Start()
{
// Initialize the previous position with the starting position
previousXPosition = transform.position.x;
}
void Update()
{
// Get the current X position
float currentXPosition = transform.position.x;
// Compare the current X position with the previous X position
if (currentXPosition > previousXPosition)
{
// Moving right
transform.rotation = Quaternion.Euler(0, 0, 0);
}
else if (currentXPosition < previousXPosition)
{
// Moving left
transform.rotation = Quaternion.Euler(0, 180, 0);
}
// Update the previous position
previousXPosition = currentXPosition;
}
}
Editor is loading...
Leave a Comment