1.工具类有三种:Screen屏幕类 Time时间类 Mathf数学类
2.Time时间类常有,常见,所以不再记录,现在是Mathf数学类,利用这个做GameOver平滑移动到屏幕中间的效果
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Gameover : MonoBehaviour {
private GUIText m_gameover; //定义类型为GUIText的对象m_gameover
public float x; //定义浮点数x
public float y; //定义浮点数y
// Use this for initialization
void Start () {
m_gameover = gameObject.GetComponent<GUIText>(); //获取GUIText组件给m_gameover
x = Screen.width / 2; //给x赋值为屏幕宽的一半
y = Screen.height / 2; //给y赋值为屏幕高的一半
}
// Update is called once per frame
void Update () {
float l=m_gameover.text.Length; //定义浮点数l,并赋值为m_gameover的字长
m_gameover.pixelOffset = new Vector2(Mathf.Lerp(-180.0f, x-l, Time.time * 0.2f), y); //对m_gameover进行二维像素偏移,Mathf插值算法从X -180到屏幕中的平滑移动,Y是不变的
//(这里有个问题就是,字不是绝对的中间,虽然减去了字长的一半,但是我把字体调大了,而l没变)
}
}