Skip to content
Snippets Groups Projects
Commit 2c2828f4 authored by Maddisss's avatar Maddisss
Browse files

Kampfsystem done

parent 555177ee
Branches Kampfsystem
No related tags found
No related merge requests found
...@@ -146,7 +146,7 @@ MonoBehaviour: ...@@ -146,7 +146,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
maxHealth: 3 maxHealth: 3
health: 0 health: 3
damageable: 0 damageable: 0
invulnerableAfterDamage: 0 invulnerableAfterDamage: 0
playerInfo: {fileID: 0} playerInfo: {fileID: 0}
...@@ -159,6 +159,28 @@ MonoBehaviour: ...@@ -159,6 +159,28 @@ MonoBehaviour:
onHeal: onHeal:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
--- !u!114 &15892653
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 15892650}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e8ff7d50993ec0343b65319b7664078e, type: 3}
m_Name:
m_EditorClassIdentifier:
layers: 8
damage: 1
damageOverTime: 0
damageEverXSeconds: 1
damagePerTick: 1
hasAttack: 1
attackPosition: {fileID: 1604040539}
attackRange: 2
affectedActors: 2
animationFinishTime: 0.9
--- !u!1 &80620903 --- !u!1 &80620903
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
...@@ -410,7 +432,7 @@ GameObject: ...@@ -410,7 +432,7 @@ GameObject:
- component: {fileID: 501061644} - component: {fileID: 501061644}
- component: {fileID: 501061643} - component: {fileID: 501061643}
- component: {fileID: 501061642} - component: {fileID: 501061642}
m_Layer: 0 m_Layer: 3
m_Name: Cube m_Name: Cube
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
...@@ -426,21 +448,21 @@ MonoBehaviour: ...@@ -426,21 +448,21 @@ MonoBehaviour:
m_GameObject: {fileID: 501061641} m_GameObject: {fileID: 501061641}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5cace9c7ea0a48a4fa7b70997311a98a, type: 3} m_Script: {fileID: 11500000, guid: 3edb2e826c9590a4d8c46dd2d83caf58, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
eventTrigger: 0 maxHealth: 3
layers: 0 health: 3
checkByTag: 0 damageable: 1
tag: [] invulnerableAfterDamage: 0
enterEvents: onDamage:
- m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
stayEvents: onDeath:
- m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
exitEvents: onHeal:
- m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
--- !u!65 &501061643 --- !u!65 &501061643
BoxCollider: BoxCollider:
...@@ -450,7 +472,7 @@ BoxCollider: ...@@ -450,7 +472,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 501061641} m_GameObject: {fileID: 501061641}
m_Material: {fileID: 0} m_Material: {fileID: 0}
m_IsTrigger: 1 m_IsTrigger: 0
m_Enabled: 1 m_Enabled: 1
serializedVersion: 2 serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1} m_Size: {x: 1, y: 1, z: 1}
...@@ -532,15 +554,15 @@ PrefabInstance: ...@@ -532,15 +554,15 @@ PrefabInstance:
m_Modifications: m_Modifications:
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.000000014901159 value: -0.000000029802319
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.000000004125767 value: -0.000000002163767
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 7.553695e-10 value: 3.9615505e-10
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
...@@ -548,11 +570,11 @@ PrefabInstance: ...@@ -548,11 +570,11 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.000000008645129 value: -0.0000000069690205
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.0000000015828008 value: 0.000000001275929
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776070906462466, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776070906462466, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_RootOrder propertyPath: m_RootOrder
...@@ -604,27 +626,31 @@ PrefabInstance: ...@@ -604,27 +626,31 @@ PrefabInstance:
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: 0.09041652 value: 0.09041651
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: 1.5116061e-16 value: 4.596334e-16
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 4.255247e-17 value: -9.266409e-20
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x propertyPath: m_LocalRotation.x
value: -0.0000000372529 value: -0.00000002235174
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y propertyPath: m_LocalRotation.y
value: -0.000000008410274 value: 0.0000000012717155
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z propertyPath: m_LocalRotation.z
value: 0.0000000015398018 value: -2.3283314e-10
objectReference: {fileID: 0}
- target: {fileID: 3158857365447649064, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_Enabled
value: 1
objectReference: {fileID: 0} objectReference: {fileID: 0}
- target: {fileID: 3158857365447649064, guid: a86eab177ff764e97a1897373332925e, type: 3} - target: {fileID: 3158857365447649064, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: stepRayLower propertyPath: stepRayLower
...@@ -638,6 +664,10 @@ PrefabInstance: ...@@ -638,6 +664,10 @@ PrefabInstance:
propertyPath: stepRayLower2 propertyPath: stepRayLower2
value: value:
objectReference: {fileID: 380224755} objectReference: {fileID: 380224755}
- target: {fileID: 3398012958249569980, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: [] m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a86eab177ff764e97a1897373332925e, type: 3} m_SourcePrefab: {fileID: 100100000, guid: a86eab177ff764e97a1897373332925e, type: 3}
--- !u!1 &1486070605 stripped --- !u!1 &1486070605 stripped
...@@ -645,6 +675,36 @@ GameObject: ...@@ -645,6 +675,36 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 142786442075079187, guid: a86eab177ff764e97a1897373332925e, type: 3} m_CorrespondingSourceObject: {fileID: 142786442075079187, guid: a86eab177ff764e97a1897373332925e, type: 3}
m_PrefabInstance: {fileID: 1435488303} m_PrefabInstance: {fileID: 1435488303}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &1604040539
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1604040540}
m_Layer: 0
m_Name: AttackPosition
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1604040540
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1604040539}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -0.26741314, y: 1.3737164, z: 0.8802147}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 15892651}
m_RootOrder: 6
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1626715799 --- !u!1 &1626715799
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
......
...@@ -2,15 +2,119 @@ using System; ...@@ -2,15 +2,119 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem;
public class DamageDealer : MonoBehaviour public class DamageDealer : MonoBehaviour
{ {
public LayerMask layermask;
public int damage = 1; public int damage = 1;
public bool damageOverTime = false;
public float damageEveryXSeconds;
public int damagePerTick = 1;
public bool hasAttack = false;
public GameObject attackPosition;
public float attackRange;
public DamageActor affectedActors; public DamageActor affectedActors;
[SerializeField] private float animationFinishTime = 0.9f;
private bool isAttacking;
private int isAttackingHash;
private bool canTakeDamage = true;
private Animator animator;
private PlayerInput input;
private InputAction attack;
private void Awake()
{
input = new PlayerInput();
animator = GetComponent<Animator>();
isAttackingHash = Animator.StringToHash("attack");
}
private void OnEnable()
{
input.Enable();
input.Player.Attack.started += Attack;
}
private void OnDisable()
{
input.Player.Attack.started -= Attack;
input.Disable();
}
private void FixedUpdate()
{
if (isAttacking && animator.GetCurrentAnimatorStateInfo(1).normalizedTime >= animationFinishTime)
{
isAttacking = false;
}
}
private void OnTriggerEnter(Collider other) private void OnTriggerEnter(Collider other)
{ {
throw new NotImplementedException(); var damageable = other.GetComponent<Damageable>();
if (hasAttack || !affectedActors.HasFlag(damageable.Actor) || damageOverTime || layermask != (layermask | (1<< other.gameObject.layer)))
return;
damageable.Damage(damage);
}
private void OnTriggerStay(Collider other)
{
var damageable = other.GetComponent<Damageable>();
if (hasAttack || !affectedActors.HasFlag(damageable.Actor) || !damageOverTime || layermask != (layermask | (1<< other.gameObject.layer)))
return;
if (canTakeDamage)
{
StartCoroutine(DamagePerSecond(damageEveryXSeconds));
damageable.Damage(damagePerTick);
}
}
private IEnumerator DamagePerSecond(float value)
{
canTakeDamage = false;
yield return new WaitForSecondsRealtime(value);
canTakeDamage = true;
} }
private void Attack(InputAction.CallbackContext obj)
{
if (!isAttacking && hasAttack)
{
animator.SetTrigger(isAttackingHash);
StartCoroutine(InitializeAttack());
Debug.Log("Attack");
Collider[] hitEnemies = Physics.OverlapSphere(attackPosition.transform.position, attackRange, layermask);
foreach (var enemy in hitEnemies)
{
if (layermask == (layermask | (1<< enemy.gameObject.layer)))
Debug.Log("layermask works");
var damageable = enemy.GetComponent<Damageable>();
if (!affectedActors.HasFlag(damageable.Actor))
return;
damageable.Damage(damage);
}
}
}
IEnumerator InitializeAttack()
{
yield return new WaitForSeconds(0.1f);
isAttacking = true;
}
private void OnDrawGizmosSelected()
{
Gizmos.DrawWireSphere(attackPosition.transform.position, attackRange);
}
} }
...@@ -6,8 +6,8 @@ using UnityEngine; ...@@ -6,8 +6,8 @@ using UnityEngine;
public abstract class Damageable : MonoBehaviour public abstract class Damageable : MonoBehaviour
{ {
public int maxHealth; [SerializeField] protected int maxHealth;
public int health; [SerializeField] protected int health;
public bool damageable; public bool damageable;
...@@ -18,7 +18,7 @@ public abstract class Damageable : MonoBehaviour ...@@ -18,7 +18,7 @@ public abstract class Damageable : MonoBehaviour
private void Awake() private void Awake()
{ {
health = maxHealth; Health = MaxHealth;
} }
public virtual int MaxHealth public virtual int MaxHealth
...@@ -48,8 +48,8 @@ public abstract class Damageable : MonoBehaviour ...@@ -48,8 +48,8 @@ public abstract class Damageable : MonoBehaviour
{ {
if (amount == 0) return; if (amount == 0) return;
amount = Mathf.Abs(amount); amount = Mathf.Abs(amount);
health -= amount; Health -= amount;
if (health <= 0) Death(); if (Health <= 0) Death();
if (invulnerableAfterDamage != 0) StartCoroutine(MakeInvulnerable(invulnerableAfterDamage)); if (invulnerableAfterDamage != 0) StartCoroutine(MakeInvulnerable(invulnerableAfterDamage));
} }
...@@ -60,7 +60,7 @@ public abstract class Damageable : MonoBehaviour ...@@ -60,7 +60,7 @@ public abstract class Damageable : MonoBehaviour
if (amount == 0) if (amount == 0)
return; return;
amount = Mathf.Abs(amount); amount = Mathf.Abs(amount);
health += amount; Health += amount;
} }
public virtual void Death() public virtual void Death()
......
...@@ -32,7 +32,7 @@ public class EnemyDamageable : Damageable ...@@ -32,7 +32,7 @@ public class EnemyDamageable : Damageable
public override void Damage(int amount) public override void Damage(int amount)
{ {
base.Damage(amount); base.Damage(amount);
Debug.Log(gameObject.name+ " Hit");
onDamage?.Invoke(); onDamage?.Invoke();
//Animation //Animation
...@@ -54,6 +54,7 @@ public class EnemyDamageable : Damageable ...@@ -54,6 +54,7 @@ public class EnemyDamageable : Damageable
base.Death(); base.Death();
onDamage.Invoke(); onDamage.Invoke();
Debug.Log(gameObject.name+" Dead");
//Animation //Animation
//Sound //Sound
......
...@@ -13,9 +13,23 @@ public class PlayerDamageable : Damageable ...@@ -13,9 +13,23 @@ public class PlayerDamageable : Damageable
public UnityEvent onHeal; public UnityEvent onHeal;
public override DamageActor Actor { get; } = DamageActor.Player; public override DamageActor Actor { get; } = DamageActor.Player;
public override int MaxHealth
{
get => playerInfo.maxHealth;
set
{
if (value == playerInfo.maxHealth)
return;
int difference = value - playerInfo.maxHealth;
playerInfo.maxHealth = value;
Heal(difference);
}
}
public override int Health public override int Health
{ {
...@@ -34,7 +48,7 @@ public class PlayerDamageable : Damageable ...@@ -34,7 +48,7 @@ public class PlayerDamageable : Damageable
public override void Damage(int amount) public override void Damage(int amount)
{ {
base.Damage(amount); base.Damage(amount);
Debug.Log("Player Damaged");
onDamage?.Invoke(); onDamage?.Invoke();
//Animation //Animation
...@@ -54,7 +68,7 @@ public class PlayerDamageable : Damageable ...@@ -54,7 +68,7 @@ public class PlayerDamageable : Damageable
public override void Death() public override void Death()
{ {
base.Death(); base.Death();
Debug.Log("Player Died");
onDamage.Invoke(); onDamage.Invoke();
//Animation //Animation
......
...@@ -43,13 +43,12 @@ public class PlayerMovement : MonoBehaviour ...@@ -43,13 +43,12 @@ public class PlayerMovement : MonoBehaviour
// Hash references // Hash references
isJumpingUpHash = Animator.StringToHash("jump"); isJumpingUpHash = Animator.StringToHash("jump");
isJumpingDownHash = Animator.StringToHash("down"); isJumpingDownHash = Animator.StringToHash("down");
isAttackingHash = Animator.StringToHash("attack");
} }
private void OnEnable() private void OnEnable()
{ {
input.Player.Jump.started += DoJump; input.Player.Jump.started += DoJump;
input.Player.Attack.started += DoAttack;
move = input.Player.Movement; move = input.Player.Movement;
input.Player.Enable(); input.Player.Enable();
...@@ -58,7 +57,6 @@ public class PlayerMovement : MonoBehaviour ...@@ -58,7 +57,6 @@ public class PlayerMovement : MonoBehaviour
private void OnDisable() private void OnDisable()
{ {
input.Player.Jump.started -= DoJump; input.Player.Jump.started -= DoJump;
input.Player.Attack.started -= DoAttack;
input.Player.Disable(); input.Player.Disable();
} }
...@@ -137,20 +135,6 @@ public class PlayerMovement : MonoBehaviour ...@@ -137,20 +135,6 @@ public class PlayerMovement : MonoBehaviour
} }
} }
private void DoAttack(InputAction.CallbackContext obj)
{
if (!isAttacking)
{
animator.SetTrigger(isAttackingHash);
StartCoroutine(InitializeAttack());
}
}
IEnumerator InitializeAttack()
{
yield return new WaitForSeconds(0.1f);
isAttacking = true;
}
private bool IsGrounded() private bool IsGrounded()
{ {
......
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8f1eaa3258b22794fb4240121cb711d3, type: 3}
m_Name: PlayerInfo
m_EditorClassIdentifier:
defaultMaxHealth: 3
defaultHealth: 3
maxHealth: 3
health: 3
fileFormatVersion: 2
guid: c15ca0934a7074f4b8a85e282b1c0f2c
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment