Änderungen am 19.03.2025 in der Schule getroffen.

This commit is contained in:
2025-03-19 14:35:19 +01:00
parent dc1338e821
commit c359b8e1b0
83 changed files with 4463 additions and 109 deletions

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
/// <summary>
/// Link zum OG Script: https://www.youtube.com/watch?v=vNL4WYgvwd8
@@ -9,6 +10,8 @@ public class Health : MonoBehaviour
public int maxHealth = 5;
public int currentHealth = 5;
public Image healthbar;
public GameObject spawnScanner;
public bool noRepeat = true;
// health logic
void Start()
@@ -19,9 +22,22 @@ public class Health : MonoBehaviour
// take dmg logic
private void Update()
{
HeightDeathZone();
TakeDamage();
}
private void HeightDeathZone()
{
if (transform.position.y <= -5 && noRepeat)
{
noRepeat = false;
GetComponent<PlayerScore>().UpdateHighScore();
spawnScanner.GetComponent<SpawnScanner>().stopSpawn();
spawnScanner.GetComponent<BoxCollider2D>().enabled = false;
SceneManager.LoadSceneAsync("MenuScene");
}
}
void TakeDamage()
{
// code from Christian

View File

@@ -1,6 +1,4 @@
using System;
using Unity.VisualScripting.FullSerializer;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
/// <summary>

View File

@@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerScore : MonoBehaviour
{
[SerializeField] private Text scoreText;
[SerializeField] private Text highScoreText;
private int score;
private int highscore;
private float counter;
// Start is called before the first frame update
void Start()
{
highscore = PlayerPrefs.GetInt("highscore", 0);
highScoreText.text = $"High Score: {highscore}";
scoreText.text = $"Score: {score}";
}
// Update is called once per frame
void Update()
{
counter += Time.deltaTime;
if (counter >= 1)
{
score++;
counter = 0;
scoreText.text = $"Score: {score}";
}
}
public void UpdateHighScore()
{
Debug.Log(highscore);
Debug.Log(score);
if (score > highscore)
{
highscore = score;
PlayerPrefs.SetInt("highscore", highscore);
}
}
}

View File

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

View File

@@ -4,16 +4,44 @@ using UnityEngine;
public class SpawnScanner : MonoBehaviour
{
// Prefabs
[SerializeField] private GameObject platform;
[SerializeField] private GameObject enemy;
public bool isAllowedToSpawn = true;
// Platform Spawner
private void OnTriggerExit2D(Collider2D collision)
{
Spawn();
if (collision.gameObject.tag.Equals("Ground") && isAllowedToSpawn)
{
Spawn();
}
}
private void Spawn()
{
float height = Random.Range(-2f, -1f);
Vector3 positionPLat = new Vector3(12f, height, 0f);
Instantiate(platform, positionPLat, Quaternion.identity);
GameObject newPlatform = Instantiate(platform, positionPLat, Quaternion.identity);
int w<EFBFBD>rfel = Random.Range(1, 4);
if (w<EFBFBD>rfel == 3)
{
SpawnEnemy(newPlatform);
}
}
// Enemy spawns on platform
private void SpawnEnemy(GameObject platformAdress)
{
Vector3 enemyPosition = platformAdress.transform.position + new Vector3(0f, 1f, 0f);
GameObject newEnemy = Instantiate(enemy, enemyPosition, Quaternion.identity);
// Enemy moves along the platform
newEnemy.transform.parent = platformAdress.transform;
}
public void stopSpawn()
{
isAllowedToSpawn = false;
}
}

View File

@@ -14,15 +14,21 @@ public class Stamina : MonoBehaviour
void Start()
{
currentStamina = maxStamina;
RefreshStaminaBar();
}
// Update is called once per frame
private void Update()
{
UseStamina();
}
void UseStamina()
public void UseStamina()
{
}
private void RefreshStaminaBar()
{
// code from Christian
staminabar.fillAmount = (float)currentStamina / (float)maxStamina;