using System.Collections; using System.Collections.Generic; using UnityEngine; public class Random2D : MonoBehaviour { public float accelerationTime = 1f; public float maxSpeed = 0.1f; private Vector3 movement; private float timeLeft; void Update() { timeLeft -= Time.deltaTime; if (timeLeft <= 0) { movement = new Vector3(Random.Range(-1f, 1f), Random.Range(-1f, 1f), 0f); timeLeft += accelerationTime; } } void FixedUpdate() { transform.position += movement * maxSpeed; } }