Advertisement
kadyr

Untitled

Oct 31st, 2021
966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     //переменная здоровья
  8.     private int health;
  9.  
  10.     [SerializeField]
  11.     private Text hpText;
  12.  
  13.    
  14.     //объект пули
  15.     [SerializeField]
  16.     private GameObject bullet;
  17.  
  18.     //позиция появления пули
  19.     [SerializeField]
  20.     private Transform riffleStart;
  21.    
  22.  
  23.  
  24.     private void Update()
  25.     {
  26.         if (Input.GetMouseButtonDown(0))
  27.         {
  28.             var bul = Instantiate(bullet, riffleStart.position, transform.rotation);
  29.             bul.GetComponent<Bullet>().SetDirection(transform.forward);
  30.         }
  31.     }
  32.    
  33.     //метод меняющий здоровье
  34.     public void ChangeHealth(int hp)
  35.     {
  36.         health += hp;
  37.         hpText.text = health.ToString();
  38.     }
  39.  
  40.     private void Start()
  41.     {
  42.         ChangeHealth(100);
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement