Enemy and weapon update

Added IDamageable interface
Added Enemy health
Added Weapon damage
Added simple Muzzle flash
Fixed gizmo bug in enemy
This commit is contained in:
Stedd 2022-07-25 15:36:49 +02:00
parent 2a5aaca576
commit 572ff7f8cb
8 changed files with 4967 additions and 21 deletions

View File

@ -73,8 +73,11 @@ public class EnemyAI : MonoBehaviour
{
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, detectRange);
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, navMeshAgent.stoppingDistance);
if (navMeshAgent != null)
{
Gizmos.color = Color.blue;
Gizmos.DrawWireSphere(transform.position, navMeshAgent.stoppingDistance);
}
}
}

View File

@ -0,0 +1,55 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyHealth : MonoBehaviour, IDamageable
{
[SerializeField] float _maxHealth = 100f;
[SerializeField] float _health ;
private void OnEnable()
{
_health = _maxHealth;
}
private void Update()
{
if (_health <= 0)
{
print("Ded");
Destroy(gameObject);
}
}
public void ModifyHealth(float _healthChange)
{
_health += _healthChange;
}
public void SetHealth(float newHealth)
{
_health = newHealth;
}
public void SetMaxHealth(float newHealth)
{
_maxHealth = newHealth;
}
public float GetHealth()
{
return _health;
}
public float GetMaxHealth()
{
return _maxHealth;
}
public float GetHealthFactor()
{
return _health / _maxHealth;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dd51d97cd02a30c46a87b8f90059abab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
interface IDamageable
{
public void ModifyHealth(float _healthChange);
public void SetHealth(float newHealth);
public void SetMaxHealth(float newHealth);
public float GetHealth();
public float GetMaxHealth();
public float GetHealthFactor();
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d0290b6d2e8462547a0d40b67a1076e3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -258,23 +258,6 @@ Transform:
m_CorrespondingSourceObject: {fileID: 400000, guid: 5d2e4237b4429b34fae4c9eb3cd9efd5, type: 3}
m_PrefabInstance: {fileID: 101430667}
m_PrefabAsset: {fileID: 0}
--- !u!1 &191840518 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 6326861089322885425, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3}
m_PrefabInstance: {fileID: 8204767108263278737}
m_PrefabAsset: {fileID: 0}
--- !u!114 &191840520
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 191840518}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01ef216392c8f33409f2efcd91f4e510, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &195553424
PrefabInstance:
m_ObjectHideFlags: 0
@ -548,6 +531,25 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 520203987}
m_CullTransparentMesh: 1
--- !u!1 &527013396 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 1314956764262545219, guid: 3a896632310e02b468121bf09411f87e, type: 3}
m_PrefabInstance: {fileID: 3924901602849055293}
m_PrefabAsset: {fileID: 0}
--- !u!114 &527013401
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 527013396}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dd51d97cd02a30c46a87b8f90059abab, type: 3}
m_Name:
m_EditorClassIdentifier:
_maxHealth: 100
_health: 0
--- !u!1001 &529879792
PrefabInstance:
m_ObjectHideFlags: 0
@ -2550,6 +2552,10 @@ PrefabInstance:
propertyPath: reloadAction.m_Name
value: Reload
objectReference: {fileID: 0}
- target: {fileID: 5428686084875064986, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3}
propertyPath: m_Name
value: MuzzleFlash
objectReference: {fileID: 0}
- target: {fileID: 7060812621224890882, guid: c5efc39a8aaf6e64ea40e9ad573e9b47, type: 3}
propertyPath: fireAction.m_Id
value: 974fe4ce-65be-4370-b772-71ca6290711e

File diff suppressed because it is too large Load Diff

View File

@ -7,11 +7,14 @@ using UnityEngine.InputSystem;
public class Weapon : MonoBehaviour
{
[SerializeField] Camera _FpCamera;
[SerializeField] ParticleSystem _MuzzleFlash;
[SerializeField] float _range = 100f;
[SerializeField] float _weaponDamage = 25f;
private void Awake()
{
_FpCamera = FindObjectOfType<Camera>();
_MuzzleFlash = GetComponentInChildren<ParticleSystem>();
}
public void OnFire()
@ -27,8 +30,30 @@ public class Weapon : MonoBehaviour
private void Shoot()
{
Physics.Raycast(_FpCamera.transform.position, _FpCamera.transform.forward, out RaycastHit hit, _range);
Animation();
ProcessHit();
print($"{hit.transform.name} was hit!");
}
private void Animation()
{
_MuzzleFlash.Play();
}
private void ProcessHit()
{
if (Physics.Raycast(_FpCamera.transform.position, _FpCamera.transform.forward, out RaycastHit hit, _range))
{
print($"{hit.transform.name} was hit!");
}
else
{
return;
}
if (hit.transform.GetComponent<IDamageable>() != null)
{
hit.transform.GetComponent<IDamageable>().ModifyHealth(-_weaponDamage);
}
}
}