IEnumerator IMove(bool flag) { if (this.close != flag) { Vector3 target = flag ? closePos : openPos; Vector2 move = new Vector2(0, (target.y > tr.position.y) ? speed : -speed); rb.constraints = RigidbodyConstraints2D.FreezePositionX | RigidbodyConstraints2D.FreezeRotation; while (((flag == true) && (target.y > tr.position.y)) || ((flag == false) && (target.y < tr.position.y))) { movePlatformScript.ChangeVelocityObject(move); rb.velocity = move; yield return(null); } } rb.velocity = new Vector2(0, 0); rb.constraints = RigidbodyConstraints2D.FreezeAll; this.close = flag; coroutineMove = null; }
IEnumerator ITimerStop(bool move) { rb.velocity = new Vector2(0, 0); rb.constraints = RigidbodyConstraints2D.FreezeAll; float timerStop = 3f; while (timerStop >= 0f) { timerStop -= Time.deltaTime; yield return(null); } rb.constraints = RigidbodyConstraints2D.FreezeRotation | RigidbodyConstraints2D.FreezePositionX; while (true) { movePlatformScript.ChangeVelocityObject(move ? new Vector2(0, 3) : new Vector2(0, -3)); rb.velocity = move ? new Vector2(0, 3) : new Vector2(0, -3); yield return(null); } }