Änderung getroffen am 15.03.2025, um 14:47. (Game unvollständig)

This commit is contained in:
2025-03-15 14:47:42 +01:00
parent 8b29c36c54
commit 7ab25e1ae9
12 changed files with 635 additions and 639 deletions

View File

@@ -1,19 +0,0 @@
using UnityEngine;
public class GroundSpawner : MonoBehaviour
{
public GameObject groundPrefab;
public Vector3 nextSpawnPos;
void Start()
{
SpawnGround();
}
// instantiating ground
public void SpawnGround()
{
GameObject temp = Instantiate(groundPrefab, nextSpawnPos, Quaternion.identity);
nextSpawnPos = temp.transform.GetChild(1).transform.position;
}
}

View File

@@ -0,0 +1,42 @@
using UnityEngine;
/// <summary>
/// Platform generator logic
/// Original Guide on YouTube link: https://www.youtube.com/watch?v=NtY_R0g8L8E.
/// </summary>
public class PlatformGenerator : MonoBehaviour
{
[SerializeField] private Transform platformStart;
[SerializeField] private System.Collections.Generic.List<Transform> platformList;
[SerializeField] Vector2 nextSpawnPos;
private Vector2 lastEndPosition;
private void Awake()
{
Vector2 positionPlat = platformStart.Find("Endposition").position;
lastEndPosition = positionPlat;
int startingSpawnLevelPlat = 5;
for (int i = 0; i < startingSpawnLevelPlat; i++)
{
SpawnLevelPlat();
}
}
private void SpawnLevelPlat()
{
// Platform is choosed different
Transform currentPlat = platformList[Random.Range(0, platformList.Count)];
// Platform spawns
Transform lastLevelPlatTransform = SpawnLevelPlat(currentPlat, lastEndPosition);
lastEndPosition = lastLevelPlatTransform.Find("EndPosition").position;
}
private Transform SpawnLevelPlat(Transform levelPlat, Vector2 spawnPosition)
{
Transform platformLevelTransform = Instantiate(levelPlat, spawnPosition, Quaternion.identity);
return platformLevelTransform;
}
}

View File

@@ -1,3 +1,4 @@
using System;
using Unity.VisualScripting.FullSerializer;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
@@ -5,7 +6,7 @@ using UnityEngine;
/// <summary>
/// Playermovement.
/// </summary>
public class PlayerController : MonoBehaviour
public class PlayerController : MonoBehaviour
{
[SerializeField] public float speed;
[SerializeField] public float acceleration;
@@ -26,7 +27,7 @@ public class PlayerController : MonoBehaviour
{
// run logic auto
speed += acceleration * Time.deltaTime;
transform.Translate(new Vector2(1f,0f) * speed * Time.deltaTime);
transform.Translate(new Vector2(1f, 0f) * speed * Time.deltaTime);
// jump logic + jump animation
if (Input.GetKey(KeyCode.W) && isGround)
@@ -53,13 +54,4 @@ public class PlayerController : MonoBehaviour
jumpAnim.SetBool("jump", false);
}
}
// ground trigger
void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.tag == "Ground")
{
FindObjectOfType<GroundSpawner>().SpawnGround();
}
}
}