Änderung getroffen am 15.03.2025, um 14:47. (Game unvollständig)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
42
Assets/Scripts/GameScene/PlatformGenerator.cs
Normal file
42
Assets/Scripts/GameScene/PlatformGenerator.cs
Normal 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;
|
||||
}
|
||||
}
|
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user