zoukankan      html  css  js  c++  java
  • 角色头上冒数字

    /// <summary>
    /// Floating text.
    /// the GUI Text Floating system
    /// </summary>
    
    using UnityEngine;
    using System.Collections;
    
    public class FloatingText : MonoBehaviour {
    
        public GUISkin CustomSkin;// GUISkin
        public string Text = "";// Text
        public float LifeTime = 1;// Life time
        public bool FadeEnd = false;// Fade out at last 1 second before destroyed
        public Color TextColor = Color.white; // Text color
        public bool Position3D = false; // enabled when you need the text along with world 3d position
        public Vector2 Position; // 2D Position
        
        private float alpha = 1;
        private float timeTemp = 0;
    
    
    
        void Start () {
            timeTemp = Time.time;
            GameObject.Destroy(this.gameObject,LifeTime);
            if(Position3D){
                Vector3 screenPos = Camera.main.WorldToScreenPoint(this.transform.position);
                Position = new Vector2(screenPos.x,Screen.height - screenPos.y);
            }
        }
    
        void Update () {
    
            if(FadeEnd){
                if(Time.time >= ((timeTemp + LifeTime) - 1)){
                    alpha = 1.0f - (Time.time - ((timeTemp + LifeTime) - 1));
                }
            }else{
                alpha = 1.0f - ((1.0f / LifeTime) * (Time.time - timeTemp));
            }
        
            if(Position3D){
                Vector3 screenPos = Camera.main.WorldToScreenPoint(this.transform.position);
                Position = new Vector2(screenPos.x,Screen.height - screenPos.y);
            }
        
        }
    
    
        void OnGUI(){
            
            GUI.color = new Color(GUI.color.r,GUI.color.g,GUI.color.b,alpha);
            if(CustomSkin){
                GUI.skin = CustomSkin;
            }
        
            Vector2 textsize = GUI.skin.label.CalcSize(new GUIContent(Text));
            Rect rect = new Rect(Position.x - (textsize.x/2), Position.y,textsize.x,textsize.y);
    
            GUI.skin.label.normal.textColor = TextColor;
            GUI.Label(rect,Text);
    
        }
    }

     调用方式

    public void AddFloatingText(Vector3 pos,string text){
            // Adding Floating Text Effect
            if(FloatingText){
                var floattext = (GameObject)Instantiate(FloatingText,pos,transform.rotation);
                if(floattext.GetComponent<FloatingText>()){
                    floattext.GetComponent<FloatingText>().Text = text;
                }
                GameObject.Destroy(floattext,1);    
            }
        }
  • 相关阅读:
    [HAOI2015]按位或——Min-Max容斥+FWT
    HDU 4773 Problem of Apollonius——圆反演
    类欧几里得小结
    线性规划(单纯形法)知识整理
    奇怪的数学题(51nod1847)——min_25筛+杜教筛+第二类斯特林数
    CSP-S 2019 游记
    2019.11.11~2019.11.12考试总结
    2019.11.6~2019.11.7考试总结
    1019.11.1~2019.11.2考试总结
    Final-阶段站立会议4
  • 原文地址:https://www.cnblogs.com/softimagewht/p/3880256.html
Copyright © 2011-2022 走看看