一款基于卡牌的塔防游戏,类似于 Supercell 的《皇室战争》的游戏玩法(简化形式), 可以与“非智能”AI 进行比赛。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

57 行
1.7 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace UnityRoyale
{
public class HealthBar : MonoBehaviour
{
public RectTransform bar;
public GameObject wholeWidget;
private bool isHidden = true;
private float originalHP;
private float currentHP;
private Transform transformToFollow;
private Color red = new Color32(252, 35, 13, 255);
private Color blue = new Color32(31, 132, 255, 255);
public void Initialise(ThinkingPlaceable p)
{
originalHP = currentHP = p.hitPoints;
transformToFollow = p.transform;
bar.GetComponent<Image>().color = (p.faction == Placeable.Faction.Player) ? red : blue;
wholeWidget.transform.localPosition = new Vector3(0f,
(p.pType == Placeable.PlaceableType.Unit) ? 3f : 6f,
(p.pType == Placeable.PlaceableType.Unit) ? 0f : -2f); //set the vertical position based on the type of Placeable
wholeWidget.SetActive(false);
}
public void SetHealth(float newHP)
{
if(isHidden)
{
wholeWidget.SetActive(true);
isHidden = false;
}
float ratio = 0f;
if(newHP > 0f)
{
ratio = newHP/originalHP;
}
bar.localScale = new Vector3(ratio, 1f, 1f);
}
public void Move()
{
if(transformToFollow != null)
transform.position = transformToFollow.position;
}
}
}