Änderungen am 03.03.2025 getroffen.
This commit is contained in:
parent
6f7c117ad1
commit
2accb093cb
@ -1055,6 +1055,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
speed: 3
|
||||
jumpPower: 6
|
||||
groundLayer:
|
||||
serializedVersion: 2
|
||||
m_Bits: 256
|
||||
|
@ -3,7 +3,6 @@ using UnityEngine;
|
||||
/// <summary>
|
||||
/// Link zum OG Script: https://pastebin.com/jD62XeKQ
|
||||
/// </summary>
|
||||
///
|
||||
public class ParallaxCamera : MonoBehaviour
|
||||
{
|
||||
// delegate -> type; safely encapsulate a method
|
||||
|
@ -1,15 +1,21 @@
|
||||
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()
|
||||
{
|
||||
@ -21,7 +27,7 @@ public class PlayerMovement : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float horizontalInput = Input.GetAxis("Horizontal");
|
||||
horizontalInput = Input.GetAxis("Horizontal");
|
||||
|
||||
// move
|
||||
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
|
||||
@ -37,13 +43,8 @@ public class PlayerMovement : MonoBehaviour
|
||||
}
|
||||
|
||||
// wall jump logic
|
||||
if (wallJumpCooldown < 0.2f)
|
||||
if (wallJumpCooldown > 0.2f)
|
||||
{
|
||||
if (Input.GetKey(KeyCode.W) && isGrounded())
|
||||
{
|
||||
Jump();
|
||||
}
|
||||
|
||||
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
|
||||
|
||||
if (onWall() && !isGrounded())
|
||||
@ -51,18 +52,48 @@ public class PlayerMovement : MonoBehaviour
|
||||
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());
|
||||
|
||||
anim.SetBool("grounded", isGrounded());
|
||||
}
|
||||
|
||||
private void Jump()
|
||||
{
|
||||
body.velocity = new Vector2(body.velocity.x, speed);
|
||||
anim.SetTrigger("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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user