miepzerino
2023-12-15 026c01967d1ac180accca3b4e458cb9455487b21
Added fall damage
3 files modified
187 ■■■■ changed files
Assets/Scenes/GameplayScene.unity 153 ●●●●● patch | view | raw | blame | history
Assets/Scripts/Damageable.cs 2 ●●●●● patch | view | raw | blame | history
Assets/Scripts/PlayerController.cs 32 ●●●●● patch | view | raw | blame | history
Assets/Scenes/GameplayScene.unity
@@ -944,81 +944,6 @@
  m_EditorClassIdentifier: 
  cam: {fileID: 519420031}
  followTarget: {fileID: 254538002}
--- !u!1 &680455189
GameObject:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  serializedVersion: 6
  m_Component:
  - component: {fileID: 680455190}
  - component: {fileID: 680455192}
  - component: {fileID: 680455191}
  m_Layer: 5
  m_Name: HealthImage
  m_TagString: Untagged
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 0
--- !u!224 &680455190
RectTransform:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 680455189}
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: 0, y: 0, z: 0}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_ConstrainProportionsScale: 0
  m_Children: []
  m_Father: {fileID: 2064964503}
  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
  m_AnchorMin: {x: 0.0037500004, y: 0.9344482}
  m_AnchorMax: {x: 0.0037500004, y: 0.9344482}
  m_AnchoredPosition: {x: 0, y: -5}
  m_SizeDelta: {x: 480, y: 20}
  m_Pivot: {x: 0, y: 1}
--- !u!114 &680455191
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 680455189}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
  m_Name:
  m_EditorClassIdentifier:
  m_Material: {fileID: 0}
  m_Color: {r: 1, g: 1, b: 1, a: 1}
  m_RaycastTarget: 1
  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
  m_Maskable: 1
  m_OnCullStateChanged:
    m_PersistentCalls:
      m_Calls: []
  m_Sprite: {fileID: 21300000, guid: 78473520b99ac4e4e8f4bcacf6670581, type: 3}
  m_Type: 0
  m_PreserveAspect: 0
  m_FillCenter: 1
  m_FillMethod: 4
  m_FillAmount: 1
  m_FillClockwise: 1
  m_FillOrigin: 0
  m_UseSpriteMesh: 0
  m_PixelsPerUnitMultiplier: 1
--- !u!222 &680455192
CanvasRenderer:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 680455189}
  m_CullTransparentMesh: 1
--- !u!1 &727795131
GameObject:
  m_ObjectHideFlags: 0
@@ -2232,81 +2157,6 @@
  m_Script: {fileID: 11500000, guid: 1a8a05de0ac134f4f9d01bef6b9da077, type: 3}
  m_Name: 
  m_EditorClassIdentifier: 
--- !u!1 &1705998485
GameObject:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  serializedVersion: 6
  m_Component:
  - component: {fileID: 1705998486}
  - component: {fileID: 1705998488}
  - component: {fileID: 1705998487}
  m_Layer: 5
  m_Name: HealthMaxImage
  m_TagString: Untagged
  m_Icon: {fileID: 0}
  m_NavMeshLayer: 0
  m_StaticEditorFlags: 0
  m_IsActive: 0
--- !u!224 &1705998486
RectTransform:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 1705998485}
  m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
  m_LocalPosition: {x: 0, y: 0, z: 0}
  m_LocalScale: {x: 1, y: 1, z: 1}
  m_ConstrainProportionsScale: 0
  m_Children: []
  m_Father: {fileID: 2064964503}
  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
  m_AnchorMin: {x: 0.0037500004, y: 0.9344482}
  m_AnchorMax: {x: 0.0037500004, y: 0.9344482}
  m_AnchoredPosition: {x: 0, y: -5}
  m_SizeDelta: {x: 480, y: 20}
  m_Pivot: {x: 0, y: 1}
--- !u!114 &1705998487
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 1705998485}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
  m_Name:
  m_EditorClassIdentifier:
  m_Material: {fileID: 0}
  m_Color: {r: 1, g: 1, b: 1, a: 1}
  m_RaycastTarget: 1
  m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
  m_Maskable: 1
  m_OnCullStateChanged:
    m_PersistentCalls:
      m_Calls: []
  m_Sprite: {fileID: 21300000, guid: c2942e726ac8f6d4d91314b62e2bda74, type: 3}
  m_Type: 0
  m_PreserveAspect: 0
  m_FillCenter: 1
  m_FillMethod: 4
  m_FillAmount: 1
  m_FillClockwise: 1
  m_FillOrigin: 0
  m_UseSpriteMesh: 0
  m_PixelsPerUnitMultiplier: 1
--- !u!222 &1705998488
CanvasRenderer:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {fileID: 0}
  m_PrefabInstance: {fileID: 0}
  m_PrefabAsset: {fileID: 0}
  m_GameObject: {fileID: 1705998485}
  m_CullTransparentMesh: 1
--- !u!1 &1919262556
GameObject:
  m_ObjectHideFlags: 0
@@ -3491,8 +3341,6 @@
  m_Children:
  - {fileID: 1398596077}
  - {fileID: 153702489}
  - {fileID: 1705998486}
  - {fileID: 680455190}
  m_Father: {fileID: 0}
  m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
  m_AnchorMin: {x: 0, y: 0}
@@ -3513,7 +3361,6 @@
  m_Name: 
  m_EditorClassIdentifier: 
  healthText: {fileID: 153702490}
  healthImage: {fileID: 680455191}
  healthSlider: {fileID: 1398596078}
--- !u!1001 &257677327013671455
PrefabInstance:
Assets/Scripts/Damageable.cs
@@ -32,6 +32,8 @@
        {
            if (value > MaxHealth)
            {
                Debug.Log("Warum?");
                _health = MaxHealth;
            }
            else
Assets/Scripts/PlayerController.cs
@@ -8,6 +8,8 @@
{
    public float moveSpeed = 5f;
    public float maxFallSpeed = -20f;
    public float maxFallSpeedDamge = -10f;
    private float maxFallSpeedCurrent = 0f;
    Vector2 moveInput;
    Rigidbody2D rb;
@@ -15,6 +17,7 @@
    Animator animator_rotor;
    public GameObject rotorGO;
    TouchingDirections touchingDirections;
    Damageable health;
    [SerializeField]
    private bool _isMoving;
@@ -56,7 +59,9 @@
        }
    }
    public bool CanMove { get
    public bool CanMove
    {
        get
        {
            return animator.GetBool(AnimationStrings.canMove);
        }
@@ -70,6 +75,7 @@
        animator = GetComponent<Animator>();
        animator_rotor = rotorGO.GetComponent<Animator>();
        touchingDirections = GetComponent<TouchingDirections>();
        health = GetComponent<Damageable>();
    }
    private void FixedUpdate()
@@ -98,6 +104,25 @@
            {
                // moving upwards no falling
                rb.velocity = new Vector2(moveInput.x * moveSpeed, (moveInput.y * moveSpeed));
            }
        }
        if (touchingDirections.IsGrounded)
        {
            if (maxFallSpeedCurrent < maxFallSpeedDamge)
            {
                TakeFallDamage(Math.Abs((int)maxFallSpeedCurrent));
                maxFallSpeedCurrent = 0;
            }
        }
        else if (IsFlying)
        {
            maxFallSpeedCurrent = rb.velocity.y;
        }
        else
        {
            if (maxFallSpeedCurrent > rb.velocity.y)
            {
                maxFallSpeedCurrent = rb.velocity.y;
            }
        }
    }
@@ -134,6 +159,11 @@
        }
    }
    public void TakeFallDamage(int fallDamage)
    {
        health.Hit(fallDamage);
    }
    //public void OnRun(InputAction.CallbackContext context)
    //{
    //    if (context.started) // Button pressed