added reload animation and bullet limit
This commit is contained in:
@@ -6,6 +6,12 @@ namespace Darkmatter.Presentation
|
||||
public class PlayerAnimController : HumonoidAnim, IPlayerAnim
|
||||
{
|
||||
private readonly int shootHash = Animator.StringToHash("IsShooting");
|
||||
|
||||
public void PlayReloadAnim()
|
||||
{
|
||||
Debug.Log("Reloading");
|
||||
}
|
||||
|
||||
public void PlayShootAnim()
|
||||
{
|
||||
Debug.Log("player Shoot");
|
||||
|
||||
8
Assets/Darkmatter/Code/Presentation/Camera.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Camera.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44cee54525ff71e468d5c70145e8c0e6
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
30
Assets/Darkmatter/Code/Presentation/Camera/CameraService.cs
Normal file
30
Assets/Darkmatter/Code/Presentation/Camera/CameraService.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using Darkmatter.Core;
|
||||
using System;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using VContainer;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class CameraService : MonoBehaviour, ICameraService
|
||||
{
|
||||
public CinemachineThirdPersonFollow AdsCamera;
|
||||
[Inject] private IInputReader inputReader;
|
||||
public bool isAiming = false;
|
||||
private void Start()
|
||||
{
|
||||
inputReader.OnAdsCameraSwitch += SwitchADSCamera;
|
||||
AdsCamera.gameObject.SetActive(false);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
inputReader.OnAdsCameraSwitch -= SwitchADSCamera;
|
||||
}
|
||||
|
||||
private void SwitchADSCamera()
|
||||
{
|
||||
isAiming = !isAiming;
|
||||
AdsCamera.gameObject.SetActive(isAiming);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0a5885776e435440ab9d5cf33f86d63
|
||||
8
Assets/Darkmatter/Code/Presentation/Enemies.meta
Normal file
8
Assets/Darkmatter/Code/Presentation/Enemies.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99f130bb5ff02fa4e8fbb2b3269771f7
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
22
Assets/Darkmatter/Code/Presentation/Enemies/Enemy.cs
Normal file
22
Assets/Darkmatter/Code/Presentation/Enemies/Enemy.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using Darkmatter.Core;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Darkmatter.Presentation
|
||||
{
|
||||
public class Enemy : MonoBehaviour, IDamageable
|
||||
{
|
||||
public float health = 100f;
|
||||
public void Die()
|
||||
{
|
||||
Debug.Log("Dead");
|
||||
this.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void TakeDamage(float damage)
|
||||
{
|
||||
health -= damage;
|
||||
if (health <= 0) Die();
|
||||
Debug.Log("Damage Taken");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cc0904e9eef2eb42860484c3c0d2675
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
"GUID:cf1df9e1968a94c4686f2fbe5ef907fc",
|
||||
"GUID:23f9a018fbd2e1242a0525718cc761d6",
|
||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4"
|
||||
"GUID:4307f53044263cf4b835bd812fc161a4",
|
||||
"GUID:7f7d1af65c2641843945d409d28f2e20"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
Reference in New Issue
Block a user