作業要求
-
簡單粒子製作
按參考資源要求,製作一個粒子系統,參考資源
使用 3.3 節介紹,用代碼控制使之在不同場景下效果不一樣
參考博客
https://www.cnblogs.com/CaomaoUnity3d/p/5983730.html
和
https://blog.csdn.net/qq_36312878/article/details/80492125
其中,後一篇博客將粒子系統的各個參數均羅列了出來,這裏就不照搬了。
實現過程
生成ParticleSystem
創建一個空項目,添加ParticleSystem的組件,掛上材料,調節參數。
整體粒子包含:
- 中間光的模擬(midLight)
- 光暈的模擬(halo)
- 周圍星光的模擬(shining)
中間光的模擬(midLight)
(因爲我個人比較喜歡藍色,這裏就用的藍色的光啦)
光暈的模擬(halo)
周圍星光的模擬(shining)
三者都是創建在空對象的下面,因爲是粒子的整體部分,所以把它當做粒子的父類節點。
中間部分的粒子不會移動,所以Speed設置爲0,粒子的Shape可以爲Box或者Sphere,因爲主要目的是讓光暈填充完這個粒子(顯的飽滿)。
代碼控制
控制功能
模擬下礦洞,或者調入深淵中,頭上的太陽模擬
中間部分的控制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class midLightChange : MonoBehaviour {
ParticleSystem exhaust;
float size = 2f;
// Use this for initialization
void Start()
{
exhaust = GetComponent<ParticleSystem>();
}
// Update is called once per frame
void Update()
{
size = size * 0.999f;
var main = exhaust.main;
main.startSize = size;
}
}
光暈控制
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class haloChange : MonoBehaviour {
ParticleSystem exhaust;
float size = 5f;
// Use this for initialization
void Start()
{
exhaust = GetComponent<ParticleSystem>();
}
// Update is called once per frame
void Update()
{
size = size * 0.999f;
var main = exhaust.main;
main.startSize = size;
}
}
項目地址
詳見我的GitHub