Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

How to use infinite loops or alternatively repeated tasks

$
0
0
I know this is all very bad code, but it's just a concept. I want to have something walk in a square so i've given it four points and positions and have it walk there. It should work if i ran it once, but I want it to work forever. How can i make this code work? Alternatively, how can I change it to have my object work between points forever. Code: public class movement1 : MonoBehaviour { public static GameObject target; public Transform targetPos = target.transform; public Vector3 targetPosv3 = target.transform.position; public Transform targetPos2 = target.transform; public Vector3 targetPosv32 = target.transform.position; public Transform targetPos3 = target.transform; public Vector3 targetPosv33 = target.transform.position; public Transform targetPos4 = target.transform; public Vector3 targetPosv34 = target.transform.position; public float step = 100.0f * Time.deltaTime; // Update is called once per frame void Update () { Start: for (int intx = 1; intx < 30; intx++) { transform.LookAt(targetPos); transform.position = Vector3.MoveTowards(transform.position, targetPosv3, step); StartCoroutine(MyMethod()); } for (int intx = 1; intx < 30; intx++) { transform.LookAt(targetPos2); transform.position = Vector3.MoveTowards(transform.position, targetPosv32, step); StartCoroutine(MyMethod()); } for (int intx = 1; intx < 30; intx++) { transform.LookAt(targetPos3); transform.position = Vector3.MoveTowards(transform.position, targetPosv33, step); StartCoroutine(MyMethod()); } for (int intx = 1; intx < 30; intx++) { transform.LookAt(targetPos3); transform.position = Vector3.MoveTowards(transform.position, targetPosv33, step); StartCoroutine(MyMethod()); } StartCoroutine(MyMethod()); goto Start; } IEnumerator MyMethod() { yield return new WaitForSeconds(0.01f); } } It doesn't work in start or in update. What should I do? Thank you very much.

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>