需求
擁有兩張貼圖霉祸,分別是藍色坐標軸和原諒色曲線撵彻,動態(tài)加載曲線圖
方法
- 創(chuàng)建canvas弟劲,并切換RenderMode為WorldSpace
-
創(chuàng)建Empty命名為Chart作為canvas的子對象,并添加sprite盲憎、slide組件戒劫;
-
創(chuàng)建Empty命名為Line作為Chart的子對象半夷,并添加image組件;
- 給Chart添加腳本SlideChangeValue迅细,用于控制曲線顯示巫橄;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SlideChangeValue : MonoBehaviour {
Slider slide;
public float time;//變化所需時間
public float speed;//變化速度
//float value = 0;
// Use this for initialization
void Start () {
slide = gameObject.GetComponent<Slider>();
}
// Update is called once per frame
void Update () {
if (Input.GetKey(KeyCode.A))//點擊鍵盤A鍵,顯示曲線
{
slide.value = 0;
StartCoroutine("ChangeValue");
}
}
IEnumerator ChangeValue()
{
while (slide.value < 1)
{
slide.value += speed / time;
yield return new WaitForSeconds(speed);
}
}
}
- 結構圖
- 對各個組件的設置請看圖!
新手記錄學習心得茵典,僅供參考湘换!