Guest User

Untitled

a guest
Jan 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Blink : MonoBehaviour {
  7.  
  8. //public
  9. public float speed = 1.0f;
  10.  
  11. //private
  12. private Text text;
  13. private Image image;
  14. private float time;
  15.  
  16. private enum ObjType{
  17. TEXT,
  18. IMAGE
  19. };
  20. private ObjType thisObjType = ObjType.TEXT;
  21.  
  22. void Start() {
  23. //アタッチしてるオブジェクトを判別
  24. if (this.gameObject.GetComponent<Image>()) {
  25. thisObjType = ObjType.IMAGE;
  26. image = this.gameObject.GetComponent<Image>();
  27. }else if (this.gameObject.GetComponent<Text>()) {
  28. thisObjType = ObjType.TEXT;
  29. text = this.gameObject.GetComponent<Text>();
  30. }
  31. }
  32.  
  33. void Update () {
  34. //オブジェクトのAlpha値を更新
  35. if (thisObjType == ObjType.IMAGE) {
  36. image.color = GetAlphaColor(image.color);
  37. }
  38. else if (thisObjType == ObjType.TEXT) {
  39. text.color = GetAlphaColor(text.color);
  40. }
  41. }
  42.  
  43. //Alpha値を更新してColorを返す
  44. Color GetAlphaColor(Color color) {
  45. time += Time.deltaTime * 5.0f * speed;
  46. color.a = Mathf.Sin(time) * 0.5f + 0.5f;
  47.  
  48. return color;
  49. }
  50. }
Add Comment
Please, Sign In to add comment