您的位置:首页 > 其它

血条的减速衰减的制作(分前景和背景效果)

2016-03-08 18:36 417 查看
using UnityEngine;
using System.Collections;

public class Control : MonoBehaviour {
//基于NGUI的设计
//血条父类
public UISlider blood;
//血条背景
public UISprite late;
//血条长度
private float bloodLength;
//血条缩减的时候减少的速度
public float speed=4;
// Use this for initialization
void Start ()
{
//初始化血条长度
bloodLength = blood.value;
}

// Update is called once per frame
void Update ()
{
//对血条衰减值的操作
if (blood.value > 0)
{
if (Input.GetKeyDown(KeyCode.F2))
{
blood.value -= 0.1f;
}
if (Input.GetKeyDown(KeyCode.F5))
{
//衰减的值较大,能更加明显的看到背景的衰减
blood.value -= 0.3f;
}
}
if (bloodLength > blood.value)
{
bloodLength -= Time.deltaTime * speed;
//实现血条的一定速度的减少
late.transform.localScale = new Vector3(bloodLength, 1, 1);
}
else if(bloodLength<blood.value)
{
bloodLength = blood.value;
}

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: