added reload animation and feature
This commit is contained in:
@@ -8,6 +8,7 @@ namespace Darkmatter.Core
|
||||
public void Reload();
|
||||
bool canAttack { get; }
|
||||
string WeaponName { get; }
|
||||
public int AmmoCount { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Core
|
||||
{
|
||||
public interface IPlayerAnim : IHumonoidAnim
|
||||
{
|
||||
void PlayReloadAnim();
|
||||
public void PlayReloadAnim(IWeapon currentWeapon);
|
||||
void PlayShootAnim();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
@@ -56,9 +58,12 @@ namespace Darkmatter.Domain
|
||||
{
|
||||
GunWeapon.Attack();
|
||||
}
|
||||
if(GunWeapon.AmmoCount==0)
|
||||
{
|
||||
playerAnim.PlayReloadAnim(GunWeapon);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Darkmatter.Domain
|
||||
|
||||
public abstract void Attack();
|
||||
|
||||
public virtual int AmmoCount { get; protected set; }
|
||||
|
||||
public virtual void Reload()
|
||||
{
|
||||
Debug.Log("Reloading");
|
||||
|
||||
@@ -1,15 +1,42 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Animations.Rigging;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerAnimController : HumonoidAnim, IPlayerAnim
|
||||
{
|
||||
private readonly int shootHash = Animator.StringToHash("IsShooting");
|
||||
private readonly int reloadHash = Animator.StringToHash("Reload");
|
||||
public TwoBoneIKConstraint HandOnGunIK; //for gunHand Ik
|
||||
private Coroutine reloadCoroutine;
|
||||
|
||||
public void PlayReloadAnim()
|
||||
public void PlayReloadAnim(IWeapon currentWeapon)
|
||||
{
|
||||
Debug.Log("Reloading");
|
||||
if (reloadCoroutine == null)
|
||||
{
|
||||
reloadCoroutine = StartCoroutine(ReloadRoutine(currentWeapon));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator ReloadRoutine(IWeapon currentWeapon)
|
||||
{
|
||||
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);
|
||||
HandOnGunIK.weight = 1f;
|
||||
currentWeapon.Reload();
|
||||
reloadCoroutine = null;
|
||||
|
||||
}
|
||||
|
||||
public void PlayShootAnim()
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Darkmatter.Presentation
|
||||
public class Enemy : MonoBehaviour, IDamageable
|
||||
{
|
||||
public float health = 100f;
|
||||
public Animator enemyAnimator;
|
||||
public void Die()
|
||||
{
|
||||
Debug.Log("Dead");
|
||||
@@ -15,6 +16,8 @@ namespace Darkmatter.Presentation
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
health -= damage;
|
||||
enemyAnimator.SetLayerWeight(1, 1);
|
||||
enemyAnimator.SetTrigger("Hit");
|
||||
if (health <= 0) Die();
|
||||
Debug.Log("Damage Taken");
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace Darkmatter.Presentation
|
||||
{
|
||||
public class PlayerMotor : MonoBehaviour, IPlayerPawn
|
||||
{
|
||||
public TwoBoneIKConstraint IKConstraint;
|
||||
|
||||
[Header("LookSetting")]
|
||||
public Transform cinemachineFollowTarget;
|
||||
|
||||
@@ -29,13 +27,30 @@ namespace Darkmatter.Presentation
|
||||
|
||||
[Header("TurnSetting")]
|
||||
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)
|
||||
|
||||
@@ -14,13 +14,13 @@ namespace Darkmatter.Presentation
|
||||
|
||||
[Header("Weapon Data")]
|
||||
public float fireRate = 0.1f;
|
||||
public int ammoCount = 40;
|
||||
public override int AmmoCount { get; protected set; } = 40;
|
||||
private float lastUsedTime;
|
||||
public GameObject BulletHole;
|
||||
public GameObject BulletHole;
|
||||
public override string WeaponName => "Rifel";
|
||||
|
||||
|
||||
public override bool canAttack => Time.time >= lastUsedTime + fireRate && ammoCount > 0;
|
||||
public override bool canAttack => Time.time >= lastUsedTime + fireRate && AmmoCount > 0;
|
||||
|
||||
[Inject] private ITargetProvider targetProvider;
|
||||
private RaycastHit hitPoint => targetProvider.hitPoint;
|
||||
@@ -30,15 +30,10 @@ namespace Darkmatter.Presentation
|
||||
public override void Attack()
|
||||
{
|
||||
lastUsedTime = Time.time;
|
||||
ammoCount--;
|
||||
AmmoCount--;
|
||||
|
||||
PlayMuzzleFlash();
|
||||
if (hitPoint.transform != null) PlayBulletHitEffectParticle();
|
||||
|
||||
if(ammoCount <= 0) //test reload
|
||||
{
|
||||
Reload();
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowBulletHole(Vector3 spawnPos)
|
||||
@@ -66,7 +61,7 @@ namespace Darkmatter.Presentation
|
||||
public override void Reload()
|
||||
{
|
||||
base.Reload();
|
||||
ammoCount = 40;
|
||||
AmmoCount = 40;
|
||||
}
|
||||
|
||||
private void PlayMuzzleFlash()
|
||||
|
||||
Reference in New Issue
Block a user