so i’m trying to make a gameObject > Quad to move left and right in an infinite loop
public class bossMover : MonoBehaviour
{
public float speed2;
void Start()
{
bossmover();
}
void bossmover()
{
while (true)
{
GetComponent<Rigidbody>().velocity = transform.right*-1 * speed2;
if (GetComponent<Rigidbody>().position.x < -1.90f)
{
GetComponent<Rigidbody>().velocity = transform.right * speed2;
}
if (GetComponent<Rigidbody>().position.x > 2.11f)
{
GetComponent<Rigidbody>().velocity = transform.right * speed2;
}
}
}
}
Unity Engine crashes when i run the scene(speed2 value 5).
Everything works just fine in the game instead of this script.