Ä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:
2025-03-15 03:58:28 +01:00
parent 823261e1b0
commit 8b29c36c54
209 changed files with 19442 additions and 5386 deletions

View File

@@ -1,17 +0,0 @@
using UnityEngine;
public class CameraController : MonoBehaviour
{
public GameObject player;
void Start()
{
}
private void Update()
{
transform.position = new Vector3(player.transform.position.x,
player.transform.position.y,
player.transform.position.z);
}
}

View File

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

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d8138f59559ef1c4aa5e060ae1079c1f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View 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;
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 92f38e1552456084e80b86c98ff64091
guid: 8857d85e11b9fee4eb0b14c59babee26
folderAsset: yes
DefaultImporter:
externalObjects: {}

View 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);
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 122e101a488bab94a9185d5075950bd8
guid: badcee902c601654880e5774b7ec2a44
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,11 +1,13 @@
using UnityEngine;
/// <summary>
/// Link zum OG Script: https://pastebin.com/jD62XeKQ
/// Move each layer
/// Original script: https://pastebin.com/jD62XeKQ.
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
/// </summary>
public class ParallaxCamera : MonoBehaviour
{
// delegate -> type; safely encapsulate a method
public delegate void ParallaxCameraDelegate(float deltaMovement);
public ParallaxCameraDelegate onCameraTranslate;

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 604646cef6bf39c439fc4b3ef6449410
guid: 31483aaf647030c49b9772aaddc8c6f2
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@@ -1,7 +1,9 @@
using UnityEngine;
/// <summary>
/// Link zum OG Script: https://pastebin.com/ZniykeGz
/// Move each layer
/// Original script: https://pastebin.com/ZniykeGz.
/// YouTube link: https://youtu.be/MEy-kIGE-lI.
/// </summary>
public class ParallaxLayer : MonoBehaviour
@@ -15,4 +17,4 @@ public class ParallaxLayer : MonoBehaviour
transform.localPosition = newPos;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 22a3a2280dd7edb439a442cc313afe32
guid: aef6d1f03d04b16488ca52bf4c8231af
MonoImporter:
externalObjects: {}
serializedVersion: 2

View 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();
}
}
}

View File

@@ -1,42 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public GameObject Ground1, Ground2, Ground3;
bool hasGround = true;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void SpawnGround()
{
}
// platform "spawn" logic
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
hasGround = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Ground"))
{
hasGround = false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d4b4a47ebce70b848b76f1dddecae559
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.SceneManagement;
using TMPro;
using UnityEngine.SceneManagement;
public class MenuScript : MonoBehaviour
{
// time logic
public TextMeshProUGUI TimeText;
void Start()
{
Time.timeScale = 1;
}
void Update()
{
var timetoDisplay = PlayerPrefs.GetFloat("highscore");
var t0 = (int)timetoDisplay;
var m = t0 / 60;
var s = (t0 - m * 60);
var ms = (int)((timetoDisplay - t0) * 100);
TimeText.text = $"{m:00}:{s:00}:{ms:00}";
// gameObject.transform.Rotate(0, 0, -400 * Time.deltaTime);
}
public void ChangeScene()
{
SceneManager.LoadSceneAsync("GameScene");
}
public void Quit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}

View File

@@ -1,19 +0,0 @@
using UnityEngine;
using UnityEngine.SceneManagement;
public class MenuScript : MonoBehaviour
{
public void ChangeScene()
{
SceneManager.LoadSceneAsync("GameScene");
}
public void Quit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}

View File

@@ -1,50 +0,0 @@
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Link zum OG Script: https://pastebin.com/DG5jcAMZ
/// </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);
}
}
}
}

View File

@@ -1,115 +0,0 @@
using Unity.VisualScripting.FullSerializer;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
/// <summary>
/// Playermovement, sowie Animation usw. hier angeschaut: https://www.youtube.com/playlist?list=PLgOEwFbvGm5o8hayFB6skAfa8Z-mw4dPV
/// </summary>
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
[SerializeField] private float jumpPower;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private LayerMask wallLayer;
private Rigidbody2D body;
private Animator anim;
private BoxCollider2D boxCollider;
private float wallJumpCooldown;
private float horizontalInput;
private void Awake()
{
// grab references for rigidbody & animatior from gameobject
body = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
boxCollider = GetComponent<BoxCollider2D>();
}
private void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
// move
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
// flip player when moving left-right
if (horizontalInput > 0.01f)
{
transform.localScale = Vector3.one;
}
else if (horizontalInput < -0.01f)
{
transform.localScale = new Vector3(-1, 1, 1);
}
// wall jump logic
if (wallJumpCooldown > 0.2f)
{
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
if (onWall() && !isGrounded())
{
body.gravityScale = 0;
body.velocity = Vector2.zero;
}
else
{
body.gravityScale = 2;
}
if (Input.GetKey(KeyCode.W))
{
Jump();
}
}
// jumpwall cd
else
{
wallJumpCooldown += Time.deltaTime;
}
// set animator parameters
anim.SetBool("run", horizontalInput != 0);
anim.SetBool("grounded", isGrounded());
}
private void Jump()
{
if (isGrounded())
{
body.velocity = new Vector2(body.velocity.x, jumpPower);
anim.SetTrigger("jump");
}
// "climb" on wall
else if (onWall() && !isGrounded())
{
if (horizontalInput == 0)
{
body.velocity = new Vector2(-Mathf.Sign(transform.localScale.x) * 9, 0);
transform.localScale = new Vector3(-Mathf.Sign(transform.localScale.x), transform.localScale.y, transform.localScale.z);
}
else
{
body.velocity = new Vector2(-Mathf.Sign(transform.localScale.x) * 3, 6);
}
wallJumpCooldown = 0;
}
}
private void OnCollisionEnter2D(Collision2D collision)
{
}
private bool isGrounded()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, Vector2.down, 0.1f, groundLayer);
return raycastHit.collider != null;
}
private bool onWall()
{
RaycastHit2D raycastHit = Physics2D.BoxCast(boxCollider.bounds.center, boxCollider.bounds.size, 0, new Vector2(transform.localScale.x, 0), 0.1f, wallLayer);
return raycastHit.collider != null;
}
}