Änderungen am 03.03.2025 getroffen.
This commit is contained in:
parent
6f7c117ad1
commit
2accb093cb
@ -1055,6 +1055,7 @@ MonoBehaviour:
|
|||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
speed: 3
|
speed: 3
|
||||||
|
jumpPower: 6
|
||||||
groundLayer:
|
groundLayer:
|
||||||
serializedVersion: 2
|
serializedVersion: 2
|
||||||
m_Bits: 256
|
m_Bits: 256
|
||||||
|
@ -3,7 +3,6 @@ using UnityEngine;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Link zum OG Script: https://pastebin.com/jD62XeKQ
|
/// Link zum OG Script: https://pastebin.com/jD62XeKQ
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
|
||||||
public class ParallaxCamera : MonoBehaviour
|
public class ParallaxCamera : MonoBehaviour
|
||||||
{
|
{
|
||||||
// delegate -> type; safely encapsulate a method
|
// delegate -> type; safely encapsulate a method
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
using Unity.VisualScripting.FullSerializer;
|
using Unity.VisualScripting.FullSerializer;
|
||||||
|
using UnityEditor.Experimental.GraphView;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Playermovement, sowie Animation usw. hier angeschaut: https://www.youtube.com/playlist?list=PLgOEwFbvGm5o8hayFB6skAfa8Z-mw4dPV
|
||||||
|
/// </summary>
|
||||||
public class PlayerMovement : MonoBehaviour
|
public class PlayerMovement : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField] private float speed;
|
[SerializeField] private float speed;
|
||||||
|
[SerializeField] private float jumpPower;
|
||||||
[SerializeField] private LayerMask groundLayer;
|
[SerializeField] private LayerMask groundLayer;
|
||||||
[SerializeField] private LayerMask wallLayer;
|
[SerializeField] private LayerMask wallLayer;
|
||||||
private Rigidbody2D body;
|
private Rigidbody2D body;
|
||||||
private Animator anim;
|
private Animator anim;
|
||||||
private BoxCollider2D boxCollider;
|
private BoxCollider2D boxCollider;
|
||||||
private float wallJumpCooldown;
|
private float wallJumpCooldown;
|
||||||
|
private float horizontalInput;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@ -21,7 +27,7 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
float horizontalInput = Input.GetAxis("Horizontal");
|
horizontalInput = Input.GetAxis("Horizontal");
|
||||||
|
|
||||||
// move
|
// move
|
||||||
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
|
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
|
||||||
@ -37,13 +43,8 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// wall jump logic
|
// 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);
|
body.velocity = new Vector2(horizontalInput * speed, body.velocity.y);
|
||||||
|
|
||||||
if (onWall() && !isGrounded())
|
if (onWall() && !isGrounded())
|
||||||
@ -51,19 +52,49 @@ public class PlayerMovement : MonoBehaviour
|
|||||||
body.gravityScale = 0;
|
body.gravityScale = 0;
|
||||||
body.velocity = Vector2.zero;
|
body.velocity = Vector2.zero;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
body.gravityScale = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Input.GetKey(KeyCode.W))
|
||||||
|
{
|
||||||
|
Jump();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// jumpwall cd
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wallJumpCooldown += Time.deltaTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set animator parameters
|
// set animator parameters
|
||||||
anim.SetBool("run", horizontalInput != 0);
|
anim.SetBool("run", horizontalInput != 0);
|
||||||
anim.SetBool("grounded", isGrounded());
|
anim.SetBool("grounded", isGrounded());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Jump()
|
private void Jump()
|
||||||
{
|
{
|
||||||
body.velocity = new Vector2(body.velocity.x, speed);
|
if (isGrounded())
|
||||||
|
{
|
||||||
|
body.velocity = new Vector2(body.velocity.x, jumpPower);
|
||||||
anim.SetTrigger("jump");
|
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 void OnCollisionEnter2D(Collision2D collision)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user