added reload animation and bullet limit

This commit is contained in:
Mausham
2025-12-29 16:41:50 -08:00
parent 3e98a42d4e
commit 357a226e21
531 changed files with 299250 additions and 849 deletions

View File

@@ -1,14 +1,16 @@
using Darkmatter.Core;
using Darkmatter.Domain;
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Animations.Rigging;
using VContainer;
namespace Darkmatter.Presentation
{
public class PlayerMotor : MonoBehaviour, IPlayerPawn
{
public TwoBoneIKConstraint IKConstraint;
[Header("LookSetting")]
public Camera mainCamera { get; private set; }
public Transform cinemachineFollowTarget;
@@ -35,11 +37,12 @@ namespace Darkmatter.Presentation
public Transform aim;
Vector3 mouseWorldPos = Vector3.zero;
public Transform muzzlePos;
public Gun gun;
public float fireRate = 0.1f;
float nextFiretime=0;
public ParticleSystem particle;
public ParticleSystem muzzleFlashParticle;
public ParticleSystem bulletHitParticle;
public GameObject BulletHole;
[Inject] private IInputReader inputReader;
@@ -63,30 +66,64 @@ namespace Darkmatter.Presentation
{
}
public int bulletAmount = 40;
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);
//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(Time.time>=nextFiretime)
if(Time.time>=nextFiretime && bulletAmount > 0)
{
bulletAmount--;
nextFiretime = Time.time + fireRate;
gun.Init(muzzlePos.position, aim.position);
particle.Play();
Vector2 screenPoint = new Vector2(Screen.width / 2, Screen.height / 2);
Ray ray = mainCamera.ScreenPointToRay(screenPoint);
RaycastHit hit;
Physics.Raycast(ray, out hit, 100f);
if(hit.collider.GetComponent<IDamageable>() != null)
{
hit.collider.GetComponent<IDamageable>().TakeDamage(10f);
}
Vector3 spawnPos = hit.point + hit.normal * 0.01f;
GameObject bulletHit = Instantiate(BulletHole, spawnPos, Quaternion.LookRotation(hit.normal));
bulletHitParticle.transform.position = spawnPos;
bulletHitParticle.transform.rotation = Quaternion.LookRotation(hit.normal);
bulletHitParticle.Play(true);
Destroy(bulletHit,5f);
muzzleFlashParticle.Play(true);
if(bulletAmount==0)
{
StartCoroutine(Reload());
}
}
}
IEnumerator Reload()
{
IKConstraint.weight = 0f;
animator.SetLayerWeight(1, 1);
animator.SetTrigger("Reload");
yield return new WaitForSeconds(3f);
bulletAmount =40;
animator.SetLayerWeight(1, 0);
IKConstraint.weight = 1;
}
private void HandleAim()
{
Vector2 screenPoint = new Vector2(Screen.width/2, Screen.height/2);
Ray ray = mainCamera.ScreenPointToRay(screenPoint);
if(Physics.Raycast(ray,out RaycastHit hitPoint, 100f,groundLayer))
{
mouseWorldPos= hitPoint.point;
mouseWorldPos= hitPoint.point;
aim.position = mouseWorldPos;
//aim.position = Vector3.Lerp(aim.position, hitPoint.point, Time.deltaTime * smoothing);
}