endless runner

This commit is contained in:
2026-02-24 15:32:03 +01:00
parent 9d0a39d769
commit e804138c6e
6 changed files with 791 additions and 255 deletions

View File

@@ -0,0 +1,22 @@
using UnityEngine;
public class GameManager : MonoBehaviour
{
[SerializeField] private GameObject roadPrefab;
private GameObject _prevRoadInstance;
[SerializeField] private GameObject parent;
private void Start()
{
_prevRoadInstance = GameObject.Find("Road (1)");
InvokeRepeating("SpawnRoad", 2f, 2f);
}
private void SpawnRoad()
{
if (_prevRoadInstance.transform.position.z <= -45f)
{
_prevRoadInstance = Instantiate(roadPrefab, new Vector3(0.0f, -1.7f, 90f), roadPrefab.transform.rotation, parent.transform);
Debug.Log("Invoked: " + _prevRoadInstance.transform.position + " name: " + _prevRoadInstance.name);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c2a1bcc4dc40120c28e695a75a436626
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
using UnityEngine;
public class RoadController : MonoBehaviour
{
[SerializeField] private float moveSpeed = 10f;
private void Start()
{
Invoke("DestroyRoad", 30f);
}
private void Update()
{
transform.Translate(Vector3.right * (moveSpeed * Time.deltaTime));
}
private void DestroyRoad()
{
Destroy(gameObject);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d4c47359d59efd16eb21b9a95d5494ff
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: