diff --git a/Implementations/AirMovement1D.cs b/Implementations/AirMovement1D.cs index 0f4e35e..155e6b5 100644 --- a/Implementations/AirMovement1D.cs +++ b/Implementations/AirMovement1D.cs @@ -16,7 +16,12 @@ namespace Syntriax.Modules.Movement.Implementations rigid = GetComponent(); groundTrigger = GetComponentInChildren(); - groundTrigger.OnTriggered += OnGroundTrigger; + + if (groundTrigger != null) + { + groundTrigger.OnTriggered += OnGroundTrigger; + CanTakeOver = false; + } } private void OnGroundTrigger(bool isGrounded) diff --git a/Implementations/DefaultMovement.cs b/Implementations/DefaultMovement.cs new file mode 100644 index 0000000..07ee97b --- /dev/null +++ b/Implementations/DefaultMovement.cs @@ -0,0 +1,13 @@ +using UnityEngine; + +namespace Syntriax.Modules.Movement.Implementations +{ + public class DefaultMovement : MovementBase + { + public override void ApplyMovement() { } + public override void Move(float x = 0, float y = 0, float z = 0) { } + protected override void OnActivated() + => Debug.LogWarning("Default Movement is activated, this movement has no implementation, please add a Movement that you can use as a fallback with it's \"CanTakeOver\" value set to true if this was not intentional"); + protected override void OnDeactivated() { } + } +} diff --git a/Implementations/DefaultMovement.cs.meta b/Implementations/DefaultMovement.cs.meta new file mode 100644 index 0000000..a0f9864 --- /dev/null +++ b/Implementations/DefaultMovement.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c4380a0ed16452042ae61e9cf53a0e07 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Implementations/GroundMovement1D.cs b/Implementations/GroundMovement1D.cs index d635869..5271430 100644 --- a/Implementations/GroundMovement1D.cs +++ b/Implementations/GroundMovement1D.cs @@ -10,6 +10,8 @@ namespace Syntriax.Modules.Movement.Implementations protected IGroundTrigger groundTrigger = null; protected Rigidbody2D rigid = null; + private void Awake() => CanTakeOver = true; + protected override void Start() { base.Start(); @@ -18,9 +20,10 @@ namespace Syntriax.Modules.Movement.Implementations groundTrigger = GetComponentInChildren(); if (groundTrigger != null) + { groundTrigger.OnTriggered += OnGroundTrigger; - else - CanTakeOver = true; + CanTakeOver = false; + } } private void OnGroundTrigger(bool isGrounded) diff --git a/MovementController.cs b/MovementController.cs index 949717d..82f77f5 100644 --- a/MovementController.cs +++ b/MovementController.cs @@ -38,6 +38,9 @@ namespace Syntriax.Modules.Movement protected virtual void Start() { + if (GetComponent() == null) + gameObject.AddComponent(); + RecacheMovements(); toggleState = GetComponent(); } @@ -73,11 +76,6 @@ namespace Syntriax.Modules.Movement ActiveMovement = movement; return; } - - Debug.LogWarning("No IMovement found with \"CanTakeOver\" value set to true, setting the last IMovement as the ActiveMovement. Please have an IMovement that you can use as a fallback with it's \"CanTakeOver\" value always set to true.", this); - - try { ActiveMovement = Movements[Movements.Count - 1]; } - catch (System.Exception) { Debug.LogWarning("Movement Controller component needs at least one Monobehaviour attached that implements IMovement interface", this); } } public void Move(float x = 0, float y = 0, float z = 0)