I am making a 2D platformer in Unity and I programmed one of the enemies to move back and forth with the ping pong function.
I would like to change the local scale depending on which direction the character is moving.
I have tried using two if statements where if the x value of the transform is below or above a certain number it will change the local scale accordingly, but that did not work.
Here is the code for the enemy:
public class Bunny: MonoBehaviour {
float min;
float max;
[SerializeField] float movmentSpeed = 0.5f;
float movementDistance;
public bool isHit = false;
void Start() {
min = transform.position.x;
max = transform.position.x + 3;
movementDistance = max - min;
}
void Update() {
if(isHit == false) {
transform.position = new Vector3(
Mathf.PingPong(Time.time * movmentSpeed, movementDistance) + min,
transform.position.y,
transform.position.z
);
}
}
}
max
andtransform.position
and then dividing it bymovementDistance
and use this value for x factor of local scale? \$\endgroup\$