добавлены модели анимации персонажа
This commit is contained in:
1 parent
11d57bec19
commit
202a894140
824 files changed
+985212
-40
No files matched your search
@@ -24,6 +24,13 @@ public class PlayerGun : MonoBehaviour
|
||||
public Light muzzleFlashLight; // Свет вспышки (мигает при выстреле)
|
||||
public Transform gunModelTransform; // Модель оружия (для анимации отдачи)
|
||||
|
||||
[Header("Анимация и эффекты оружия (Nokobot M1911)")]
|
||||
public Animator gunAnimator; // Аниматор самого пистолета (затвор M1911)
|
||||
public Animator playerAnimator; // Аниматор персонажа (стойка, выстрел, перезарядка)
|
||||
public GameObject muzzleFlashPrefab; // Эффект дульной вспышки (Nokobot)
|
||||
public GameObject casingPrefab; // Префаб гильзы (45ACP)
|
||||
public Transform casingExitPoint; // Точка выброса гильзы
|
||||
|
||||
[Header("Экипировка оружия")]
|
||||
[Tooltip("Находится ли оружие сейчас в руках")]
|
||||
public bool isGunEquipped = false; // По умолчанию убрано в кобуру (в руках кулаки)
|
||||
@@ -51,10 +58,23 @@ public class PlayerGun : MonoBehaviour
|
||||
public bool IsEquipped => isGunEquipped;
|
||||
public bool HasGun => hasGun;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (playerAnimator == null)
|
||||
{
|
||||
playerAnimator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
mainCamera = Camera.main;
|
||||
|
||||
if (playerAnimator == null)
|
||||
{
|
||||
playerAnimator = GetComponentInChildren<Animator>();
|
||||
}
|
||||
|
||||
if (audioSource == null)
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
@@ -196,6 +216,15 @@ public class PlayerGun : MonoBehaviour
|
||||
{
|
||||
gunModelTransform.gameObject.SetActive(isGunEquipped);
|
||||
}
|
||||
|
||||
if (playerAnimator != null)
|
||||
{
|
||||
playerAnimator.SetBool("HasGun", isGunEquipped);
|
||||
if (playerAnimator.layerCount > 1)
|
||||
{
|
||||
playerAnimator.SetLayerWeight(1, isGunEquipped ? 1f : 0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void TryShoot()
|
||||
@@ -237,6 +266,39 @@ public class PlayerGun : MonoBehaviour
|
||||
StartCoroutine(MuzzleFlashRoutine());
|
||||
StartCoroutine(RecoilRoutine());
|
||||
|
||||
// Анимация затвора пистолета M1911 (Nokobot)
|
||||
if (gunAnimator != null)
|
||||
{
|
||||
gunAnimator.SetTrigger("Fire");
|
||||
}
|
||||
|
||||
// Анимация персонажа (отдача при выстреле)
|
||||
if (playerAnimator != null)
|
||||
{
|
||||
playerAnimator.SetTrigger("Shoot");
|
||||
}
|
||||
|
||||
// Спавн визуальной дульной вспышки
|
||||
if (muzzleFlashPrefab != null && muzzlePoint != null)
|
||||
{
|
||||
GameObject flash = Instantiate(muzzleFlashPrefab, muzzlePoint.position, muzzlePoint.rotation);
|
||||
Destroy(flash, 0.4f);
|
||||
}
|
||||
|
||||
// Выброс стреляной гильзы 45ACP
|
||||
if (casingPrefab != null && casingExitPoint != null)
|
||||
{
|
||||
GameObject casing = Instantiate(casingPrefab, casingExitPoint.position, casingExitPoint.rotation);
|
||||
Rigidbody rb = casing.GetComponent<Rigidbody>();
|
||||
if (rb != null)
|
||||
{
|
||||
Vector3 ejectDir = casingExitPoint.right * 1.5f + casingExitPoint.up * 1.2f + Random.insideUnitSphere * 0.3f;
|
||||
rb.AddForce(ejectDir, ForceMode.Impulse);
|
||||
rb.AddTorque(Random.insideUnitSphere * 15f, ForceMode.Impulse);
|
||||
}
|
||||
Destroy(casing, 3f);
|
||||
}
|
||||
|
||||
// Луч выстрела из камеры вперед через перекрестие
|
||||
Vector3 rayOrigin = mainCamera != null ? mainCamera.transform.position : transform.position + Vector3.up * 1.5f;
|
||||
Vector3 rayDir = mainCamera != null ? mainCamera.transform.forward : transform.forward;
|
||||
@@ -319,6 +381,12 @@ public class PlayerGun : MonoBehaviour
|
||||
audioSource.PlayOneShot(reloadSound);
|
||||
}
|
||||
|
||||
// Анимация перезарядки персонажа
|
||||
if (playerAnimator != null)
|
||||
{
|
||||
playerAnimator.SetTrigger("Reload");
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(reloadDuration);
|
||||
|
||||
int needed = magSize - currentAmmo;
|
||||
|
||||
Reference in new issue
Block a user