Erster Commit; Stand 18.02.2025.

This commit is contained in:
2025-02-18 16:06:31 +01:00
parent b7b2934c0f
commit 58508e4dec
69 changed files with 7786 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
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

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

View File

@@ -0,0 +1,10 @@
using UnityEngine;
public class KeepGameObject : MonoBehaviour
{
void Start()
{
// GameObject won't be deleted on scene switch
DontDestroyOnLoad(this.gameObject);
}
}

View File

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

View File

@@ -0,0 +1,19 @@
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

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

View File

@@ -0,0 +1,84 @@
using Unity.VisualScripting.FullSerializer;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[SerializeField] private float speed;
[SerializeField] private LayerMask groundLayer;
[SerializeField] private LayerMask wallLayer;
private Rigidbody2D body;
private Animator anim;
private BoxCollider2D boxCollider;
private float wallJumpCooldown;
private void Awake()
{
// grab references for rigidbody & animatior from gameobject
body = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
boxCollider = GetComponent<BoxCollider2D>();
}
private void Update()
{
float 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)
{
if (Input.GetKey(KeyCode.W) && isGrounded())
{
Jump();
}
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
if (onWall() && !isGrounded())
{
body.gravityScale = 0;
body.velocity = Vector2.zero;
}
}
// set animator parameters
anim.SetBool("run", horizontalInput != 0);
anim.SetBool("grounded", isGrounded());
}
private void Jump()
{
body.velocity = new Vector2(body.velocity.x, speed);
anim.SetTrigger("jump");
}
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;
}
}

View File

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

View File

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