Commit 72d47e84 authored by mthiele2's avatar mthiele2
Browse files
parents b5a9331b 62e2b8e7
...@@ -6,6 +6,7 @@ using UnityEngine; ...@@ -6,6 +6,7 @@ using UnityEngine;
public class MovingPlattform : MonoBehaviour { public class MovingPlattform : MonoBehaviour {
public List<Vector2> m_Points; public List<Vector2> m_Points;
public List<string> m_Tags;
[SerializeField] private float m_Speed = 0.3f; //plattform geschwindigkeit [SerializeField] private float m_Speed = 0.3f; //plattform geschwindigkeit
[SerializeField] private float m_Wait = 2f; //zeit in Sekunden wie lange die Plattform wartet [SerializeField] private float m_Wait = 2f; //zeit in Sekunden wie lange die Plattform wartet
[SerializeField] private int m_StartIndex = 0; //Index in der Liste an der die Plattform starten soll [SerializeField] private int m_StartIndex = 0; //Index in der Liste an der die Plattform starten soll
...@@ -94,21 +95,31 @@ public class MovingPlattform : MonoBehaviour { ...@@ -94,21 +95,31 @@ public class MovingPlattform : MonoBehaviour {
} }
//CollisionEnter mit Spieler kann um Gegner erweitert werden //CollisionEnter mit Spieler kann um Gegner erweitert werden
void OnCollisionEnter2D (Collision2D col2D) { void OnCollisionEnter2D (Collision2D col2D)
if (col2D.transform.gameObject.tag.Equals ("Player")) { {
//Setzt parent object des Spielers zu dieser Plattform somit wird die transformation der Plattform auf den Spieler Übertragen for (int i = 0; i < m_Tags.Count; i++)
col2D.transform.SetParent (gameObject.transform); {
if (m_MoveingByTouching) if (col2D.gameObject.tag.Equals(m_Tags[i]) || col2D.gameObject.tag.Equals("Player"))
Patrol (); {
} //Setzt parent object des Spielers zu dieser Plattform somit wird die transformation der Plattform auf den Spieler Übertragen
col2D.transform.SetParent (gameObject.transform);
if (m_MoveingByTouching)
Patrol ();
}
}
} }
//CollisionExit mit Spieler kann um Gegner erweitert werden //CollisionExit mit Spieler kann um Gegner erweitert werden
void OnCollisionExit2D (Collision2D col2D) { void OnCollisionExit2D (Collision2D col2D) {
if (col2D.transform.gameObject.tag.Equals ("Player")) {
//Sets Spieler Parent zu niemand for (int i = 0; i < m_Tags.Count; i++)
col2D.transform.SetParent (null); {
} if (col2D.gameObject.tag.Equals(m_Tags[i]) || col2D.gameObject.tag.Equals("Player"))
{
//Sets Spieler Parent zu niemand
col2D.transform.SetParent (null);
}
}
} }
void OnDrawGizmosSelected () { void OnDrawGizmosSelected () {
...@@ -128,4 +139,4 @@ public class MovingPlattform : MonoBehaviour { ...@@ -128,4 +139,4 @@ public class MovingPlattform : MonoBehaviour {
} }
} }
} }
} }
\ No newline at end of file
...@@ -141,16 +141,16 @@ public class MovementController : MonoBehaviour ...@@ -141,16 +141,16 @@ public class MovementController : MonoBehaviour
if (((m_Grounded) || (m_TempJumpCount > 1) || (m_Swimming && m_CanSwim)) && !m_Jumped) if (((m_Grounded) || (m_TempJumpCount > 1) || (m_Swimming && m_CanSwim)) && !m_Jumped)
{ {
// Add a vertical force to the player. // Add a vertical force to the player.
OnJumpEvent.Invoke();
m_Grounded = false; m_Grounded = false;
m_TempJumpCount--; m_TempJumpCount--;
//m_Rigidbody2D.AddForce (new Vector2 (0f, m_JumpForce)); //m_Rigidbody2D.AddForce (new Vector2 (0f, m_JumpForce));
m_Rigidbody2D.velocity = Vector2.up * m_JumpForce; m_Rigidbody2D.velocity = Vector2.up * m_JumpForce;
OnJumpEvent.Invoke();
StartCoroutine(Wait(m_SecondsWaitToJump)); StartCoroutine(Wait(m_SecondsWaitToJump));
} }
} }
if (m_Rigidbody2D.velocity.y < 0 && !m_Swimming) if (m_Rigidbody2D.velocity.y < 0 && !m_Swimming && !m_Grounded)
{ {
m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime; m_Rigidbody2D.velocity += Vector2.up * Physics2D.gravity.y * (m_fallMultiplier - 1) * Time.deltaTime;
} }
...@@ -205,11 +205,13 @@ public class MovementController : MonoBehaviour ...@@ -205,11 +205,13 @@ public class MovementController : MonoBehaviour
private void OnCollisionEnter2D(Collision2D other) private void OnCollisionEnter2D(Collision2D other)
{ {
if(other.gameObject.layer == m_WhatIsGround)
m_Airborn = false; m_Airborn = false;
} }
private void OnCollisionExit2D(Collision2D other) private void OnCollisionExit2D(Collision2D other)
{ {
if(other.gameObject.layer == m_WhatIsGround)
m_Airborn = true; m_Airborn = true;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment