using UnityEngine;
public class PlayerController : MonoBehaviour
{
[Header("Movimiento")]
public float speed = 5f;
[Header("Disparo")]
public GameObject bulletPrefab;
public Transform bulletSpawn;
public float fireRate = 1f;
private float nextFire = 0f;
public float bulletDamage = 20f;
[Header("Salud")]
public float maxHealth = 120f;
public float healthRegenSpeed = 1f; // HP por segundo
private float currentHealth;
void Start()
{
currentHealth = maxHealth;
}
void Update()
{
// Movimiento del jugador
float moveX = Input.GetAxis("Horizontal");
float moveY = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveX, moveY, 0f) * speed * Time.deltaTime;
transform.Translate(movement);
// Disparar balas con clic izquierdo
if (Input.GetMouseButton(0) && Time.time > nextFire)
{
nextFire = Time.time + 1f / fireRate;
Shoot();
}
// Regeneración de salud
currentHealth += healthRegenSpeed * Time.deltaTime;
currentHealth = Mathf.Min(currentHealth, maxHealth);
}
void Shoot()
{
Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
}
public void IncreaseBulletDamage(float amount)
{
bulletDamage += amount;
}
public void IncreaseFireRate(float amount)
{
fireRate += amount;
}
public void IncreaseMaxHealth(float amount)
{
maxHealth += amount;
currentHealth += amount; // Restaura la salud al aumentar la máxima
}
public float GetCurrentHealth()
{
return currentHealth;
}
public float GetMaxHealth()
{
return maxHealth;
}
}