UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"a infinite runner"
Here's a simple script for an infinite runner in Unity: ```csharp using UnityEngine; public class InfiniteRunner : MonoBehaviour { public float moveSpeed = 5f; public float spawnRate = 1f; public GameObject[] obstacles; public Transform spawnPoint; private float timer; void Update() { // Move the player forward transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime); // Spawn obstacles timer += Time.deltaTime; if (timer >= spawnRate) { SpawnObstacle(); timer = 0; } } void SpawnObstacle() { int randomIndex = Random.Range(0, obstacles.Length); GameObject obstacle = Instantiate(obstacles[randomIndex], spawnPoint.position, Quaternion.identity); Destroy(obstacle, 10f); // Destroy the obstacle after 10 seconds to save memory } } ``` This script will move the player forward at a constant speed and spawn obstacles at a specified rate. Attach this script to your player object and make sure to set up the obstacles and spawn point in the Inspector.