I’m making a 2D platformer in unity and I programmed one of many enemies to maneuver backwards and forwards with the ping pong operate. I wish to change the native scale relying on which course the character is shifting. I’ve tried utilizing two if statements the place if the x worth of the rework is beneath or above a sure quantity it would change the native scale accordingly however that didn’t work.
Right here is the code for the enemy:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class Bunny: MonoBehaviour
{
float min;
float max;
[SerializeField] float movmentSpeed = 0.5f;
float movementDistance;
public bool isHit = false;
// Use this for initialization
void Begin()
{
min = rework.place.x;
max = rework.place.x + 3;
movementDistance = max - min;
}
// Replace is named as soon as per body
void Replace()
{
if(isHit == false) {
rework.place = new Vector3(Mathf.PingPong(Time.time * movmentSpeed, movementDistance) + min, rework.place.y, rework.place.z);
}
}
}
thanks upfront