Änderungen am 15.03.2025 um 03:58 Uhr zuhause getroffen.
(Mache nach 2-4h Schlaf weiter. Noch nicht ganz fertig, aufgrund aufgrund mangelnder Zeit durch Arbeit, damaligen privaten Problemen und damals zu viel vorgenommen).
This commit is contained in:
19
Assets/Scripts/GameScene/GroundSpawner.cs
Normal file
19
Assets/Scripts/GameScene/GroundSpawner.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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;
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/GroundSpawner.cs.meta
Normal file
11
Assets/Scripts/GameScene/GroundSpawner.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a58f8ab6811b9942b34b7598fe7d37f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
37
Assets/Scripts/GameScene/Health.cs
Normal file
37
Assets/Scripts/GameScene/Health.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
/// <summary>
|
||||
/// Link zum OG Script: https://www.youtube.com/watch?v=vNL4WYgvwd8
|
||||
/// </summary>
|
||||
public class Health : MonoBehaviour
|
||||
{
|
||||
public int maxHealth = 5;
|
||||
public int currentHealth = 5;
|
||||
public Image healthbar;
|
||||
|
||||
// health logic
|
||||
void Start()
|
||||
{
|
||||
currentHealth = maxHealth;
|
||||
}
|
||||
|
||||
// take dmg logic
|
||||
private void Update()
|
||||
{
|
||||
TakeDamage();
|
||||
}
|
||||
|
||||
void TakeDamage()
|
||||
{
|
||||
// code from Christian
|
||||
healthbar.fillAmount = (float)currentHealth / (float)maxHealth;
|
||||
|
||||
if (currentHealth <= 0)
|
||||
{
|
||||
// player is dead
|
||||
// death animation
|
||||
// game over screen
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/Health.cs.meta
Normal file
11
Assets/Scripts/GameScene/Health.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: abeb25a7ebccdd549a934791ddc6ca61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/GameScene/Parallax.meta
Normal file
8
Assets/Scripts/GameScene/Parallax.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8857d85e11b9fee4eb0b14c59babee26
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
49
Assets/Scripts/GameScene/Parallax/ParallaxBackground.cs
Normal file
49
Assets/Scripts/GameScene/Parallax/ParallaxBackground.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Move each layer
|
||||
/// Original script: https://pastebin.com/DG5jcAMZ.
|
||||
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
|
||||
/// </summary>
|
||||
|
||||
public class ParallaxBackground : MonoBehaviour
|
||||
{
|
||||
public ParallaxCamera parallaxCamera;
|
||||
List<ParallaxLayer> parallaxLayers = new List<ParallaxLayer>();
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (parallaxCamera == null)
|
||||
parallaxCamera = Camera.main.GetComponent<ParallaxCamera>();
|
||||
|
||||
if (parallaxCamera != null)
|
||||
parallaxCamera.onCameraTranslate += Move;
|
||||
|
||||
SetLayers();
|
||||
}
|
||||
|
||||
void SetLayers()
|
||||
{
|
||||
parallaxLayers.Clear();
|
||||
|
||||
for (int i = 0; i < transform.childCount; i++)
|
||||
{
|
||||
ParallaxLayer layer = transform.GetChild(i).GetComponent<ParallaxLayer>();
|
||||
|
||||
if (layer != null)
|
||||
{
|
||||
layer.name = "Layer-" + i;
|
||||
parallaxLayers.Add(layer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Move(float delta)
|
||||
{
|
||||
foreach (ParallaxLayer layer in parallaxLayers)
|
||||
{
|
||||
layer.Move(delta);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/Parallax/ParallaxBackground.cs.meta
Normal file
11
Assets/Scripts/GameScene/Parallax/ParallaxBackground.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: badcee902c601654880e5774b7ec2a44
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
34
Assets/Scripts/GameScene/Parallax/ParallaxCamera.cs
Normal file
34
Assets/Scripts/GameScene/Parallax/ParallaxCamera.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Move each layer
|
||||
/// Original script: https://pastebin.com/jD62XeKQ.
|
||||
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
|
||||
/// </summary>
|
||||
|
||||
public class ParallaxCamera : MonoBehaviour
|
||||
{
|
||||
public delegate void ParallaxCameraDelegate(float deltaMovement);
|
||||
public ParallaxCameraDelegate onCameraTranslate;
|
||||
|
||||
private float oldPosition;
|
||||
|
||||
void Start()
|
||||
{
|
||||
oldPosition = transform.position.x;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (transform.position.x != oldPosition)
|
||||
{
|
||||
if (onCameraTranslate != null)
|
||||
{
|
||||
float delta = oldPosition - transform.position.x;
|
||||
onCameraTranslate(delta);
|
||||
}
|
||||
|
||||
oldPosition = transform.position.x;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/Parallax/ParallaxCamera.cs.meta
Normal file
11
Assets/Scripts/GameScene/Parallax/ParallaxCamera.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31483aaf647030c49b9772aaddc8c6f2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/GameScene/Parallax/ParallaxLayer.cs
Normal file
20
Assets/Scripts/GameScene/Parallax/ParallaxLayer.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Move each layer
|
||||
/// Original script: https://pastebin.com/ZniykeGz.
|
||||
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
|
||||
/// </summary>
|
||||
|
||||
public class ParallaxLayer : MonoBehaviour
|
||||
{
|
||||
public float parallaxFactor;
|
||||
|
||||
public void Move(float delta)
|
||||
{
|
||||
Vector3 newPos = transform.localPosition;
|
||||
newPos.x -= delta * parallaxFactor;
|
||||
|
||||
transform.localPosition = newPos;
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/Parallax/ParallaxLayer.cs.meta
Normal file
11
Assets/Scripts/GameScene/Parallax/ParallaxLayer.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aef6d1f03d04b16488ca52bf4c8231af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
65
Assets/Scripts/GameScene/PlayerController.cs
Normal file
65
Assets/Scripts/GameScene/PlayerController.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using Unity.VisualScripting.FullSerializer;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Playermovement.
|
||||
/// </summary>
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] public float speed;
|
||||
[SerializeField] public float acceleration;
|
||||
[SerializeField] public float jumpPower;
|
||||
|
||||
private Rigidbody2D body;
|
||||
private bool isGround = true;
|
||||
|
||||
private Animator jumpAnim;
|
||||
|
||||
void Start()
|
||||
{
|
||||
body = this.GetComponent<Rigidbody2D>();
|
||||
jumpAnim = this.GetComponent<Animator>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// run logic auto
|
||||
speed += acceleration * Time.deltaTime;
|
||||
transform.Translate(new Vector2(1f,0f) * speed * Time.deltaTime);
|
||||
|
||||
// jump logic + jump animation
|
||||
if (Input.GetKey(KeyCode.W) && isGround)
|
||||
{
|
||||
Jump();
|
||||
jumpAnim.SetBool("jump", true);
|
||||
isGround = false;
|
||||
}
|
||||
}
|
||||
|
||||
// jump method logic + jump animation
|
||||
void Jump()
|
||||
{
|
||||
Vector2 velocity = body.velocity;
|
||||
velocity.y = jumpPower;
|
||||
body.velocity = velocity;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
if (other.collider.tag == "Ground")
|
||||
{
|
||||
isGround = true;
|
||||
jumpAnim.SetBool("jump", false);
|
||||
}
|
||||
}
|
||||
|
||||
// ground trigger
|
||||
void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (other.gameObject.tag == "Ground")
|
||||
{
|
||||
FindObjectOfType<GroundSpawner>().SpawnGround();
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/PlayerController.cs.meta
Normal file
11
Assets/Scripts/GameScene/PlayerController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aec587ad29831fa4086120cb404dce39
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/GameScene/Stamina.cs
Normal file
39
Assets/Scripts/GameScene/Stamina.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
/// <summary>
|
||||
/// code is similar to health
|
||||
/// </summary>
|
||||
public class Stamina : MonoBehaviour
|
||||
{
|
||||
|
||||
public int maxStamina = 9;
|
||||
public int currentStamina = 9;
|
||||
public Image staminabar;
|
||||
|
||||
// stamina logic
|
||||
void Start()
|
||||
{
|
||||
currentStamina = maxStamina;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
private void Update()
|
||||
{
|
||||
UseStamina();
|
||||
}
|
||||
|
||||
void UseStamina()
|
||||
{
|
||||
// code from Christian
|
||||
staminabar.fillAmount = (float)currentStamina / (float)maxStamina;
|
||||
|
||||
// cd for stamina
|
||||
|
||||
// stamina reg
|
||||
|
||||
if (currentStamina < 0)
|
||||
{
|
||||
// longer cd for stamina reg
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/GameScene/Stamina.cs.meta
Normal file
11
Assets/Scripts/GameScene/Stamina.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9db9cb377ddbbb94f8fc783165e50e5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user