HW9
1. 血条(Health Bar)的预制设计
具体要求如下
- 分别使用 IMGUI 和 UGUI 实现
- 使用 UGUI,血条是游戏对象的一个子元素,任何时候需要面对主摄像机
- 分析两种实现的优缺点
- 给出预制的使用方法
IMGUI
使用一个红色的 cube 作为血条,并设置其跟随任务(Ethan)移动。而血条的减少,我是通过改变其localScale来是实现的。在 cube 上挂载一个脚本,并检测点击事件,检测到鼠标点击时, cube 的长度减少 0.1 这样就做成了血条减少的效果。
具体代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class blood : MonoBehaviour
{
float padding = 0;
public Transform t;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
this.transform.pos