You've already forked zumbi-game
apply language lints
This commit is contained in:
@@ -1,20 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class ZombieController : MonoBehaviour
|
||||
{
|
||||
private static readonly int DieHash = Animator.StringToHash("Die");
|
||||
private static readonly int IsAttackingHash = Animator.StringToHash("isAttacking");
|
||||
private static readonly int IsWalkingHash = Animator.StringToHash("isWalking");
|
||||
private static readonly int IsRunningHash = Animator.StringToHash("isRunning");
|
||||
|
||||
[Header("Health")]
|
||||
private float maxHealth = 50;
|
||||
private readonly float maxHealth = 50;
|
||||
private float currentHealth;
|
||||
|
||||
[Header("Movement")]
|
||||
private float walkSpeed = 1f;
|
||||
private float runSpeed = 2f;
|
||||
private float runDistance = 5f; // od kedy začne bežať
|
||||
private float attackDistance = 1.5f; // od kedy útočí
|
||||
private readonly float walkSpeed = 1f;
|
||||
private readonly float runSpeed = 2f;
|
||||
private readonly float runDistance = 5f; // od kedy začne bežať
|
||||
private readonly float attackDistance = 1.5f; // od kedy útočí
|
||||
|
||||
[Header("Attack")]
|
||||
private float attackDamage = 10f;
|
||||
private float attackCooldown = 1f;
|
||||
private readonly float attackDamage = 10f;
|
||||
private readonly float attackCooldown = 1f;
|
||||
private float lastAttackTime;
|
||||
|
||||
private Transform player;
|
||||
@@ -46,35 +52,35 @@ public class ZombieController : MonoBehaviour
|
||||
else if (distance <= runDistance)
|
||||
{
|
||||
MoveToPlayer(runSpeed);
|
||||
animator.SetBool("isRunning", true);
|
||||
animator.SetBool("isWalking", false);
|
||||
animator.SetBool("isAttacking", false);
|
||||
animator.SetBool(IsRunningHash, true);
|
||||
animator.SetBool(IsWalkingHash, false);
|
||||
animator.SetBool(IsAttackingHash, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveToPlayer(walkSpeed);
|
||||
animator.SetBool("isWalking", true);
|
||||
animator.SetBool("isRunning", false);
|
||||
animator.SetBool("isAttacking", false);
|
||||
animator.SetBool(IsWalkingHash, true);
|
||||
animator.SetBool(IsRunningHash, false);
|
||||
animator.SetBool(IsAttackingHash, false);
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveToPlayer(float speed)
|
||||
{
|
||||
Vector3 direction = (player.position - transform.position).normalized;
|
||||
transform.position += direction * speed * Time.deltaTime;
|
||||
transform.position += speed * Time.deltaTime * direction;
|
||||
transform.LookAt(new Vector3(player.position.x, transform.position.y, player.position.z));
|
||||
}
|
||||
|
||||
private void StopMoving()
|
||||
{
|
||||
animator.SetBool("isWalking", false);
|
||||
animator.SetBool("isRunning", false);
|
||||
animator.SetBool(IsWalkingHash, false);
|
||||
animator.SetBool(IsRunningHash, false);
|
||||
}
|
||||
|
||||
private void TryAttack()
|
||||
{
|
||||
animator.SetBool("isAttacking", true);
|
||||
animator.SetBool(IsAttackingHash, true);
|
||||
|
||||
if (Time.time - lastAttackTime >= attackCooldown)
|
||||
{
|
||||
@@ -96,7 +102,7 @@ public class ZombieController : MonoBehaviour
|
||||
private void Die()
|
||||
{
|
||||
Debug.Log($"{gameObject.name} je mŕtvy!");
|
||||
animator.SetTrigger("Die");
|
||||
animator.SetTrigger(DieHash);
|
||||
Destroy(gameObject, 2f);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user