This Script crashes my unity

my script keeps crashing mt unity when i press play even though there are no errors in the script

using UnityEngine;
using System.Collections;

public class Foot_Left : MonoBehaviour {

public Transform LeftFoot;
public Transform Middle;
public Transform RightFoot;
public bool Walking;
bool AlwaysTrue = true;
Rigidbody2D rbody;

void Start () {	
	
	rbody = this.GetComponent<Rigidbody2D>();

}

void Update () {
	
	while (AlwaysTrue == true) {
	
		StartCoroutine(wait());
	
	}

}

IEnumerator wait () {

	rbody.drag = 0;
	yield return new WaitForSeconds(3);
	rbody.AddForce (transform.right);
	yield return new WaitForSeconds(5);
	rbody.drag = 10000000;

}

}

You’ve got an infinite loop in your Update() function. If I had to take a guess at what you were trying to achieve, is it this?

using UnityEngine; 
using System.Collections;

public class Foot_Left : MonoBehaviour {

     public Transform LeftFoot;
     public Transform Middle;
     public Transform RightFoot;
     public bool Walking;
     bool AlwaysTrue = true;
     Rigidbody2D rbody;

     void Start () {        
         rbody = this.GetComponent<Rigidbody2D>();
         StartCoroutine(wait());
     }

     IEnumerator wait () {
       while (AlwaysTrue == true) {
         rbody.drag = 0;
         yield return new WaitForSeconds(3);
         rbody.AddForce (transform.right);
         yield return new WaitForSeconds(5);
         rbody.drag = 10000000;
       }
     }

}

How many times you need to repeat this action in the game ? If you need do it once maybe you have to put aside the loop instances like Update method or While structure. Or, if you want to activate it when the user presses a key or any other process is enable, you have to initialize the AlwaysTrue value in false and change it with another method to true. I hope this help. Regards…

Also you don’t need a variable called AlwaysTrue you can simply just have

while(true) { }