Sorry if my title was not clear. My script needs to fix the method of movement object. In my script, the Z axis angel of main object moves with the target object on Y axis. If target goes under zero value, main object goes back smoothly. But, if target goes up from "part 2 to part 1"...it just be there.I don't know how to invert or reverse the movement. Here is my script
public Transform target;
public float dis, zz;
// Update is called once per frame
void Update()
{
dis = transform.position.y - target.transform.position.y;
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, zz);
// part 1
if (dis < 0.0f && dis > -0.3f)
{
zz -= Time.deltaTime * 0.2f;
if (zz <= -0.3f)
{
zz = -0.3f;
}
}
// part 2
if (dis < 0.31f && dis > -0.6f)
{
zz -= Time.deltaTime * 0.2f;
if (zz <= -0.6f)
{
zz = -0.6f;
}
}
// part 3
if (dis < 0.61f && dis > -0.9f)
{
zz -= Time.deltaTime * 0.2f;
if (zz <= -0.9f)
{
zz = -0.9f;
}
}
}