Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class MovingUpDown : MonoBehaviour {
- public float minY, maxY;
- public float speed = 1;
- public float waitTime = 1;
- delegate bool Condition();
- IEnumerator Moving ()
- {
- int direction = 1;
- while (true)
- {
- Condition isMoving;
- if (direction == 1)
- isMoving = () => { return transform.position.y < maxY; };
- else
- isMoving = () => { return transform.position.y > minY; };
- while (isMoving())
- {
- yield return null;
- transform.Translate(Vector3.up * direction * speed * Time.deltaTime);
- }
- yield return new WaitForSeconds(waitTime);
- direction *= -1;
- }
- }
- void Start ()
- {
- StartCoroutine(Moving());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement