您的当前位置:首页正文

UGUI基础+image+技能冷却更新

来源:花图问答

1.UGUI:用户界面,Unity自带的UI系统,4.6版本以上

NGUI:外部插件


2.Canvas:画布,所有的UI控件都是Canvas的子物体.

EventSystem:事件系统(交互/不可交互,点击/触摸/拖拽)

Canvas Scale:Scale With Screen Size(Height:1)适配于高度


3.Rect Transform - Transform(深度:与前后关系有关)

Rect Transform组件

Posx/Posy:以控件空心圆表示的位置

Width/Height:四个蓝色的点围成的矩形的宽高

Pivot:轴心,左下角为(0,0),取值范围0-1

Anchors:锚点(适配),相对于父级,左下角为(0,0),取值范围0-1,控件的矩形的四条边始终距离锚点组成的四条边保持不变

操作:

1.先选中某个点,Alt键以中心点缩放

2.先选中某个点,Shift键等比例缩放

3.先选中某个点,Shift+Alt以中心点等比缩放.

Strecth:

1.黄色表示锚点所在位置

2.Shift:蓝色:表示轴心点,同时设置轴心点

3.Alt:同时设置位置,白色的边表示控件的四条边

Image:图片

Source Image:图片(Sprite)

Color:叠加在原本图片上

Raycast Target:能否接受射线碰撞(能否被点击一系列)

Imgae Type:

Simple:普通类型

Sliced:九宫格切图

Tiled:平铺

Filled:填充()

ClockWise:逆时针

Set Native Size:保持图片原有大小


4.技能冷却更新

private Image ColdImage;//技能冷却图片  

 private bool IsCold = false;   

 public float ColdTime = 5f;//技能冷却的时间为5s   

 private float time = 0;//计时    

private Text TimeText;

// Use this for initializationvoid Start () {     

  ColdImage = GetComponent<Image>();       

   TimeText = transform.parent.Find("Seconed").GetComponent<Text>();

//设置显示文本不激活

TimeText.gameObject.SetActive(false);

}

// Update is called once per frame

void Update () {

if(Input.GetKeyDown(KeyCode.Alpha1) && !IsCold)

{

//开始技能冷却

IsCold = true;

//fillAmount

ColdImage.fillAmount = 1;

//

TimeText.gameObject.SetActive(true);

//

TimeText.text = ColdTime.ToString();

}

if(IsCold)

{

time += Time.deltaTime;

//改变fillAomunt从1-0

ColdImage.fillAmount = 1 - time / ColdTime;

TimeText.text = (ColdTime - time).ToString();

if(ColdImage.fillAmount <= 0)

{

ColdImage.fillAmount = 0;

IsCold = false;

time = 0;

TimeText.gameObject.SetActive(false);

}