Generic class of enemy & first enemy: Mayor
This commit is contained in:
@@ -4,8 +4,9 @@ using UnityEngine;
|
||||
|
||||
public class PlayerManager : MonoBehaviour
|
||||
{
|
||||
public float Health = 100f;
|
||||
public float Speed = 10f;
|
||||
public int Health = 100;
|
||||
public int MaxHealth = 100;
|
||||
public float Speed = 2f;
|
||||
public int Exp = 0;
|
||||
public int Level = 1;
|
||||
|
||||
@@ -19,4 +20,27 @@ public class PlayerManager : MonoBehaviour
|
||||
Level++;
|
||||
}
|
||||
}
|
||||
|
||||
public void TakeDamage(int value)
|
||||
{
|
||||
Health -= value;
|
||||
if (Health < 0)
|
||||
{
|
||||
Health = 0;
|
||||
|
||||
// Death animation + menu
|
||||
} else
|
||||
{
|
||||
// Damage animation
|
||||
}
|
||||
}
|
||||
|
||||
public void Heal(int value)
|
||||
{
|
||||
Health += value;
|
||||
if (Health > MaxHealth)
|
||||
{
|
||||
Health = MaxHealth;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(SpriteRenderer)), RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(SpriteRenderer)), RequireComponent(typeof(Animator)), RequireComponent(typeof(PlayerManager))]
|
||||
public class PlayerMovements : MonoBehaviour
|
||||
{
|
||||
private readonly float _speed = .15f;
|
||||
|
||||
private SpriteRenderer _sr;
|
||||
private Animator _animator;
|
||||
private PlayerManager _pm;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_sr = GetComponent<SpriteRenderer>();
|
||||
_animator = GetComponent<Animator>();
|
||||
_pm = GetComponent<PlayerManager>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
/** --- Move player along 2D axis ----------------------------------*/
|
||||
float moveH = Input.GetAxis("Horizontal") * _speed;
|
||||
float moveV = Input.GetAxis("Vertical") * _speed;
|
||||
float moveH = Input.GetAxis("Horizontal") * _pm.Speed * Time.deltaTime;
|
||||
float moveV = Input.GetAxis("Vertical") * _pm.Speed * Time.deltaTime;
|
||||
|
||||
transform.Translate(new Vector2(moveH, moveV));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user