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