started building logics for enemy
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyAnimationController : MonoBehaviour
|
||||
{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2db86e800d68dad4d98796670a91a679
|
||||
@@ -16,27 +16,27 @@ namespace Darkmatter.Presentation
|
||||
public TwoBoneIKConstraint HandOnGunIK; //for gunHand Ik
|
||||
private Coroutine reloadCoroutine;
|
||||
|
||||
public void PlayReloadAnim(IWeapon currentWeapon)
|
||||
public void PlayReloadAnim(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
if (reloadCoroutine == null)
|
||||
{
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(currentWeapon));
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(reloadableWeapon));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ReloadRoutine(IWeapon currentWeapon)
|
||||
IEnumerator ReloadRoutine(IReloadableWeapon reloadableWeapon)
|
||||
{
|
||||
reloadableWeapon.isReloading = true;
|
||||
yield return BlendLayerWeight(1, 1, 0.2f);
|
||||
//animator.SetLayerWeight(1,1);
|
||||
HandOnGunIK.weight = 0f;
|
||||
animator.SetTrigger(reloadHash);
|
||||
|
||||
yield return new WaitForSeconds(3f); //gave the length of the animation very bad practice
|
||||
|
||||
// animator.SetLayerWeight(1, 0);
|
||||
yield return BlendLayerWeight(1, 0, 0.2f);
|
||||
HandOnGunIK.weight = 1f;
|
||||
currentWeapon.Reload();
|
||||
reloadableWeapon.Reload();
|
||||
reloadableWeapon.isReloading = false;
|
||||
reloadCoroutine = null;
|
||||
|
||||
}
|
||||
|
||||
23
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
23
Assets/Darkmatter/Code/Presentation/Enemies/EnemyMotor.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class EnemyMotor : MonoBehaviour
|
||||
{
|
||||
[SerializeField] NavMeshAgent enemyAI;
|
||||
public Transform playerTransform;
|
||||
|
||||
[Header("Enemy Data")]
|
||||
public float walkSpeed = 3f;
|
||||
public float chaseSpeed = 5f;
|
||||
public float visionRange = 15f;
|
||||
public float attackRange = 2f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
enemyAI.SetDestination(playerTransform.position);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df95acdebfef05045a08adb2e752fd26
|
||||
@@ -29,28 +29,10 @@ namespace Darkmatter.Presentation
|
||||
public float turnSpeed = 5f;
|
||||
[Inject] private PlayerConfigSO playerConfig;
|
||||
|
||||
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
private void HandleShooting()
|
||||
{
|
||||
//float shootingWeight = animator.GetLayerWeight(1);
|
||||
//float targetWeight = inputReader.isShooting ? 1 : 0;
|
||||
//float setshootingWeight = Mathf.Lerp(shootingWeight, targetWeight, Time.deltaTime * 5);
|
||||
//animator.SetLayerWeight(1, setshootingWeight);
|
||||
//animator.SetBool("IsShooting", inputReader.isShooting);
|
||||
|
||||
//if (!inputReader.isShooting) return;
|
||||
//if(gunWeapon.canAttack)
|
||||
//{
|
||||
// gunWeapon.Attack();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
//state based functions
|
||||
public void Move(Vector3 motion)
|
||||
|
||||
@@ -6,7 +6,7 @@ using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class GunWeapon : WeaponBase
|
||||
public class GunWeapon : MonoBehaviour, IReloadableWeapon
|
||||
{
|
||||
[Header("VFX")]
|
||||
public ParticleSystem MuzzleFlashParticle;
|
||||
@@ -14,24 +14,21 @@ namespace Darkmatter.Presentation
|
||||
|
||||
[Header("Weapon Data")]
|
||||
public float fireRate = 0.1f;
|
||||
[SerializeField] private int ammoCount = 40;
|
||||
public bool isReloading { get; set; }
|
||||
public int AmmoCount { get; set; } = 40;
|
||||
public int initialAmmoCount { get; set; } = 40;
|
||||
private float lastUsedTime;
|
||||
public GameObject BulletHole;
|
||||
public override string WeaponName => "Rifel";
|
||||
public override int AmmoCount { get => this.ammoCount; set => ammoCount = value; }
|
||||
|
||||
|
||||
public override bool canAttack => Time.time >= lastUsedTime + fireRate && ammoCount > 0;
|
||||
public bool canAttack => Time.time >= lastUsedTime + fireRate && AmmoCount > 0 && !isReloading;
|
||||
|
||||
[Inject] private ITargetProvider targetProvider;
|
||||
private RaycastHit hitPoint => targetProvider.hitPoint;
|
||||
|
||||
|
||||
|
||||
public override void Attack()
|
||||
public void Attack()
|
||||
{
|
||||
lastUsedTime = Time.time;
|
||||
ammoCount--;
|
||||
AmmoCount--;
|
||||
|
||||
PlayMuzzleFlash();
|
||||
if (hitPoint.transform != null) PlayBulletHitEffectParticle();
|
||||
@@ -55,14 +52,13 @@ namespace Darkmatter.Presentation
|
||||
|
||||
BulletHitEffectParticle.transform.position = spawnPos;
|
||||
BulletHitEffectParticle.transform.rotation = Quaternion.LookRotation(hitPoint.normal);
|
||||
|
||||
|
||||
BulletHitEffectParticle.Play(true);
|
||||
}
|
||||
|
||||
public override void Reload()
|
||||
public void Reload()
|
||||
{
|
||||
base.Reload();
|
||||
ammoCount = maxAmmoCount;
|
||||
AmmoCount = initialAmmoCount;
|
||||
}
|
||||
|
||||
private void PlayMuzzleFlash()
|
||||
|
||||
Reference in New Issue
Block a user