Реализованы классы Damager и Hitbox
This commit is contained in:
parent
8b7b8830fc
commit
9ecc66aea1
8
Assets/Scripts/Gameplay/Core.meta
Normal file
8
Assets/Scripts/Gameplay/Core.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 14fb34962344db448b981ce94efdde4d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
32
Assets/Scripts/Gameplay/Core/Damager.cs
Normal file
32
Assets/Scripts/Gameplay/Core/Damager.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
[RequireComponent (typeof(Collider))]
|
||||
public class Damager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int Damage;
|
||||
private GameObject Owner;
|
||||
|
||||
public UnityEvent OnCollision;
|
||||
|
||||
public void Initialize(GameObject Owner)
|
||||
{
|
||||
if (OnCollision == null) OnCollision = new();
|
||||
|
||||
this.Owner = Owner;
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.TryGetComponent<Hitbox>(out var hitbox))
|
||||
{
|
||||
//Коллизия с собой
|
||||
if (hitbox.Owner == this.Owner) return;
|
||||
|
||||
hitbox.TakeDamage(Damage);
|
||||
}
|
||||
|
||||
OnCollision?.Invoke();
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/Core/Damager.cs.meta
Normal file
2
Assets/Scripts/Gameplay/Core/Damager.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b9c4414025683b40ace934a0c1be3f5
|
||||
11
Assets/Scripts/Gameplay/Core/Hitbox.cs
Normal file
11
Assets/Scripts/Gameplay/Core/Hitbox.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent (typeof(Collider))]
|
||||
public class Hitbox : MonoBehaviour
|
||||
{
|
||||
public GameObject Owner { get; private set; }
|
||||
public event Action<int> OnDamage;
|
||||
public void Initialize(GameObject Owner) => this.Owner = Owner;
|
||||
public void TakeDamage(int damage) => OnDamage?.Invoke(damage);
|
||||
}
|
||||
2
Assets/Scripts/Gameplay/Core/Hitbox.cs.meta
Normal file
2
Assets/Scripts/Gameplay/Core/Hitbox.cs.meta
Normal file
@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc7a89df164d2684b9953c773b371384
|
||||
Loading…
x
Reference in New Issue
Block a user