This script is supposed to move an object between two different cubes but it keeps crashing my unity no idea why i added a counter to get rid of the infinite loop but still crashes any idea i’m still pretty new to coding btw if you have a better suggestion for the movement between two cubes i would love to hear it thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MoveAsteroid : MonoBehaviour {
public Transform Target;
public Transform Target2;
public int speed;
public int reset = 1;
public int count = 0;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
float step = speed * Time.deltaTime;
while (reset == 1)
{
transform.position = Vector3.MoveTowards(transform.position, Target.position, step);
if (transform.position == Target.position) {
reset = 2;
count++;
}
}
while (reset == 2) {
transform.position = Vector3.MoveTowards(transform.position, Target2.position, step);
if(transform.position == Target2.position) {
reset = 1;
count++;
}
}
if(count == 5)
{
reset = 0;
}
}
}