Я пытаюсь уменьшить панель здоровья игрока, когда он сталкивается с вражеским лазером, но написанный мной скрипт не работает и выдает следующую ошибку:
Активы / Скрипты/Laser/HealthManager.cs(19,21): ошибка CS0029: невозможно неявное преобразование типа void 'в UnityEngine.UI.Slider.
Может кто-то потратить некоторое время и просмотреть мой код и сказать, почемупанель здоровья не работает?Спасибо.
Сценарий HealthManager:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HealthManager : MonoBehaviour {
public int CurrentHealth { get; set; }
public int MaxHealth { get; set; }
public Slider HealthBar;
//public GameObject LaserBulletEnemyPreFab;
//public GameObject PlayerPrefab;
//public LaserLevelManager myLevelmanager;
// Use this for initialization
void Start () {
MaxHealth = 20;
CurrentHealth = MaxHealth; //Resseting the health on start
HealthBar = CalculatingHealth();
}
// Update is called once per frame
void Update()
{
if(GetComponent<Collider>().gameObject.tag == "EnemyLaser")
{
Destroy(GetComponent<Collider>().gameObject);
DealDamage(1);
}
}
void DealDamage(int DamageValue)
{
CurrentHealth -= DamageValue; //Deduct the damage dealt from the player's health
HealthBar = CalculatingHealth();
if(CurrentHealth <= 0) //If health is 0
{
PlayerDead(); //Calling the function
}
}
void CalculatingHealth()
{
int healthdecrease = CurrentHealth / MaxHealth;
}
void PlayerDead()
{
CurrentHealth = 0; //Currenthealth is 0
LaserLevelManager.LoadLevel("Lose"); //Take player to the lose scene
}
}