Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class CoroutineExample : MonoBehaviour
- {
- private Transform _transform;
- private readonly float _limit = 5f;
- private IEnumerator _coroutine;
- private void Awake() => _transform = GetComponent<Transform>();
- private void Start()
- {
- _coroutine = CoroutineWithCondition(_transform, _limit);
- if (_transform != null) StartCoroutine(_coroutine);
- }
- private IEnumerator CoroutineWithCondition(Transform t, float limit)
- {
- while (t.position.x < limit)
- {
- t.Translate(Vector3.right * Time.deltaTime, Space.World);
- yield return null;
- }
- Debug.Log("Transform has reached the limit");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement