Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlayerController : MonoBehaviour
- {
- //переменная здоровья
- private int health;
- [SerializeField]
- private Text hpText;
- //объект пули
- [SerializeField]
- private GameObject bullet;
- //позиция появления пули
- [SerializeField]
- private Transform riffleStart;
- private void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- var bul = Instantiate(bullet, riffleStart.position, transform.rotation);
- bul.GetComponent<Bullet>().SetDirection(transform.forward);
- }
- }
- //метод меняющий здоровье
- public void ChangeHealth(int hp)
- {
- health += hp;
- hpText.text = health.ToString();
- }
- private void Start()
- {
- ChangeHealth(100);
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Health"))
- {
- Destroy(other.transform.parent.gameObject);
- ChangeHealth(50);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement