Question by
nedvdd42 · Feb 20, 2018 at 10:10 PM ·
movementprogramminglooplooping
Can't figure out how to make this work without it looping?
I want to close a door after x seconds, but i can't get the door to close without it being on a continuous loop? I don't understand it, but could someone show me how to make this door close after x seconds, but it will only close once? using UnityEngine; using System.Collections; public class DoorClose : MonoBehaviour { public Transform farEnd; private Vector3 startPosition; private Vector3 endPosition; private float secondsForOneLength = 2f; private bool closed = false;
void Start()
{
startPosition = transform.position;
endPosition = farEnd.position;
}
void Update()
{
if (closed == false)
{
CloseDoor();
//closed = true;
}
}
void CloseDoor()
{
transform.position = Vector3.Lerp(startPosition, endPosition, Mathf.SmoothStep(0f, 1f, Mathf.PingPong(Time.time / secondsForOneLength, 1f)));
}
}
Comment
void CloseDoor()
{
transform.position = Vector3.Lerp(startPosition, endPosition, $$anonymous$$athf.SmoothStep(0f, 1f, $$anonymous$$athf.PingPong(Time.time / secondsForOneLength, 1f)));
closed = true;
}
?
How about this :
private void CloseDoor()
{
transform.position = Vector3.Lerp(startPosition, endPosition, $$anonymous$$athf.SmoothStep(0f, 1f, $$anonymous$$athf.PingPong(Time.time / secondsForOneLength, 1f)));
if(transform.position == endPosition)closed = true;
}
Your answer
Follow this Question
Related Questions
Unity freezes. I dont know why... 3 Answers
Player rapidly stutters back and forth while moving 0 Answers
Magnetic pieces being attached to each other and moving together ??? 0 Answers
Problems with loops 2 Answers
Camera Follow Problem 0 Answers