1. 先在Assets目錄,按右鍵選擇New Import Asset,匯入新的影像。
2. 影像不能直接用在人機介面(UI)上,必須先轉成Sprite (2D and UI)才能使用,如下圖。
3.接下來我們新增一個Canvas物件,並在Canvas物件下分別產生 5個Image物件,在Image物件中,放入在步驟2做的一個Sprite。4.撰寫程式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class NewBehaviourScript : MonoBehaviour {
private float startTime;
private float alpha = 1.0f;
[SerializeField]
private int m_time = 8;
[SerializeField]
private CanvasGroup m_canvasGroup;
// Use this for initialization
void Start () {
startTime = Time.time;
}
// Update is called once per frame
void FixedUpdate()
{
if (Time.time - startTime > m_time)
{
if (alpha > 0)
{
alpha -= 0.01f;
m_canvasGroup.alpha = alpha;
}
}
}
}
沒有留言:
張貼留言