document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using UnityEngine;
  2.  
  3. public class PlayerController : MonoBehaviour
  4. {
  5.     [Header("Movimiento")]
  6.     public float speed = 5f;
  7.  
  8.     [Header("Disparo")]
  9.     public GameObject bulletPrefab;
  10.     public Transform bulletSpawn;
  11.     public float fireRate = 1f;
  12.     private float nextFire = 0f;
  13.     public float bulletDamage = 20f;
  14.  
  15.     [Header("Salud")]
  16.     public float maxHealth = 120f;
  17.     public float healthRegenSpeed = 1f; // HP por segundo
  18.     private float currentHealth;
  19.  
  20.     void Start()
  21.     {
  22.         currentHealth = maxHealth;
  23.     }
  24.  
  25.     void Update()
  26.     {
  27.         // Movimiento del jugador
  28.         float moveX = Input.GetAxis("Horizontal");
  29.         float moveY = Input.GetAxis("Vertical");
  30.         Vector3 movement = new Vector3(moveX, moveY, 0f) * speed * Time.deltaTime;
  31.         transform.Translate(movement);
  32.  
  33.         // Disparar balas con clic izquierdo
  34.         if (Input.GetMouseButton(0) && Time.time > nextFire)
  35.         {
  36.             nextFire = Time.time + 1f / fireRate;
  37.             Shoot();
  38.         }
  39.  
  40.         // Regeneración de salud
  41.         currentHealth += healthRegenSpeed * Time.deltaTime;
  42.         currentHealth = Mathf.Min(currentHealth, maxHealth);
  43.     }
  44.  
  45.     void Shoot()
  46.     {
  47.         Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation);
  48.     }
  49.  
  50.     public void IncreaseBulletDamage(float amount)
  51.     {
  52.         bulletDamage += amount;
  53.     }
  54.  
  55.     public void IncreaseFireRate(float amount)
  56.     {
  57.         fireRate += amount;
  58.     }
  59.  
  60.     public void IncreaseMaxHealth(float amount)
  61.     {
  62.         maxHealth += amount;
  63.         currentHealth += amount; // Restaura la salud al aumentar la máxima
  64.     }
  65.  
  66.     public float GetCurrentHealth()
  67.     {
  68.         return currentHealth;
  69.     }
  70.  
  71.     public float GetMaxHealth()
  72.     {
  73.         return maxHealth;
  74.     }
  75. }
  76.  
');