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

Kampfsystem done

parent 555177ee
No related branches found
No related tags found
No related merge requests found
......@@ -146,7 +146,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
maxHealth: 3
health: 0
health: 3
damageable: 0
invulnerableAfterDamage: 0
playerInfo: {fileID: 0}
......@@ -159,6 +159,28 @@ MonoBehaviour:
onHeal:
m_PersistentCalls:
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
GameObject:
m_ObjectHideFlags: 0
......@@ -410,7 +432,7 @@ GameObject:
- component: {fileID: 501061644}
- component: {fileID: 501061643}
- component: {fileID: 501061642}
m_Layer: 0
m_Layer: 3
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
......@@ -426,21 +448,21 @@ MonoBehaviour:
m_GameObject: {fileID: 501061641}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5cace9c7ea0a48a4fa7b70997311a98a, type: 3}
m_Script: {fileID: 11500000, guid: 3edb2e826c9590a4d8c46dd2d83caf58, type: 3}
m_Name:
m_EditorClassIdentifier:
eventTrigger: 0
layers: 0
checkByTag: 0
tag: []
enterEvents:
- m_PersistentCalls:
maxHealth: 3
health: 3
damageable: 1
invulnerableAfterDamage: 0
onDamage:
m_PersistentCalls:
m_Calls: []
stayEvents:
- m_PersistentCalls:
onDeath:
m_PersistentCalls:
m_Calls: []
exitEvents:
- m_PersistentCalls:
onHeal:
m_PersistentCalls:
m_Calls: []
--- !u!65 &501061643
BoxCollider:
......@@ -450,7 +472,7 @@ BoxCollider:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 501061641}
m_Material: {fileID: 0}
m_IsTrigger: 1
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 1, y: 1, z: 1}
......@@ -532,15 +554,15 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x
value: -0.000000014901159
value: -0.000000029802319
objectReference: {fileID: 0}
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y
value: -0.000000004125767
value: -0.000000002163767
objectReference: {fileID: 0}
- target: {fileID: 2964776070120258367, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z
value: 7.553695e-10
value: 3.9615505e-10
objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x
......@@ -548,11 +570,11 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y
value: -0.000000008645129
value: -0.0000000069690205
objectReference: {fileID: 0}
- target: {fileID: 2964776070640493478, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z
value: 0.0000000015828008
value: 0.000000001275929
objectReference: {fileID: 0}
- target: {fileID: 2964776070906462466, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_RootOrder
......@@ -604,27 +626,31 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x
value: 0.09041652
value: 0.09041651
objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y
value: 1.5116061e-16
value: 4.596334e-16
objectReference: {fileID: 0}
- target: {fileID: 2964776071172871079, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.z
value: 4.255247e-17
value: -9.266409e-20
objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.x
value: -0.0000000372529
value: -0.00000002235174
objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_LocalRotation.y
value: -0.000000008410274
value: 0.0000000012717155
objectReference: {fileID: 0}
- target: {fileID: 2964776071241958025, guid: a86eab177ff764e97a1897373332925e, type: 3}
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}
- target: {fileID: 3158857365447649064, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: stepRayLower
......@@ -638,6 +664,10 @@ PrefabInstance:
propertyPath: stepRayLower2
value:
objectReference: {fileID: 380224755}
- target: {fileID: 3398012958249569980, guid: a86eab177ff764e97a1897373332925e, type: 3}
propertyPath: m_Enabled
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: a86eab177ff764e97a1897373332925e, type: 3}
--- !u!1 &1486070605 stripped
......@@ -645,6 +675,36 @@ GameObject:
m_CorrespondingSourceObject: {fileID: 142786442075079187, guid: a86eab177ff764e97a1897373332925e, type: 3}
m_PrefabInstance: {fileID: 1435488303}
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
GameObject:
m_ObjectHideFlags: 0
......
......@@ -2,15 +2,119 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class DamageDealer : MonoBehaviour
{
public LayerMask layermask;
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;
[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)
{
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;
public abstract class Damageable : MonoBehaviour
{
public int maxHealth;
public int health;
[SerializeField] protected int maxHealth;
[SerializeField] protected int health;
public bool damageable;
......@@ -18,7 +18,7 @@ public abstract class Damageable : MonoBehaviour
private void Awake()
{
health = maxHealth;
Health = MaxHealth;
}
public virtual int MaxHealth
......@@ -48,8 +48,8 @@ public abstract class Damageable : MonoBehaviour
{
if (amount == 0) return;
amount = Mathf.Abs(amount);
health -= amount;
if (health <= 0) Death();
Health -= amount;
if (Health <= 0) Death();
if (invulnerableAfterDamage != 0) StartCoroutine(MakeInvulnerable(invulnerableAfterDamage));
}
......@@ -60,7 +60,7 @@ public abstract class Damageable : MonoBehaviour
if (amount == 0)
return;
amount = Mathf.Abs(amount);
health += amount;
Health += amount;
}
public virtual void Death()
......
......@@ -32,7 +32,7 @@ public class EnemyDamageable : Damageable
public override void Damage(int amount)
{
base.Damage(amount);
Debug.Log(gameObject.name+ " Hit");
onDamage?.Invoke();
//Animation
......@@ -54,6 +54,7 @@ public class EnemyDamageable : Damageable
base.Death();
onDamage.Invoke();
Debug.Log(gameObject.name+" Dead");
//Animation
//Sound
......
......@@ -13,9 +13,23 @@ public class PlayerDamageable : Damageable
public UnityEvent onHeal;
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
{
......@@ -34,7 +48,7 @@ public class PlayerDamageable : Damageable
public override void Damage(int amount)
{
base.Damage(amount);
Debug.Log("Player Damaged");
onDamage?.Invoke();
//Animation
......@@ -54,7 +68,7 @@ public class PlayerDamageable : Damageable
public override void Death()
{
base.Death();
Debug.Log("Player Died");
onDamage.Invoke();
//Animation
......
......@@ -43,13 +43,12 @@ public class PlayerMovement : MonoBehaviour
// Hash references
isJumpingUpHash = Animator.StringToHash("jump");
isJumpingDownHash = Animator.StringToHash("down");
isAttackingHash = Animator.StringToHash("attack");
}
private void OnEnable()
{
input.Player.Jump.started += DoJump;
input.Player.Attack.started += DoAttack;
move = input.Player.Movement;
input.Player.Enable();
......@@ -58,7 +57,6 @@ public class PlayerMovement : MonoBehaviour
private void OnDisable()
{
input.Player.Jump.started -= DoJump;
input.Player.Attack.started -= DoAttack;
input.Player.Disable();
}
......@@ -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()
{
......
%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