完善官方的“汽车尾气”
-
启动时喷射蓝红火焰,达到一定速度时喷出黑烟
- 故障时,冒黑烟
汽车尾气粒子构建步骤
-
在Shape模块中选择Box形状
- 在Render模块中选择Material
使用样例中的ParticleSmokeBlack
- 在Color Over Lifetime模块中改变alpha值(调整透明度)
模拟烟雾的稀疏
- 在Size Over Lifetime模块中设置粒子随时间变大
模拟烟雾的扩散
- 在Force Over Lifetime模块中设置(0,0,-0.75)的力使粒子运动随时间变慢
- 在主模块中设置Gravity Modifier为-0.05,模拟烟雾向上飘动
模拟粒子的运动
- 在主模块中设置Start Rotation为随机值
生成随机的粒子
- 调整粒子的生存时间、初始大小、初始速度、发射速率、最大粒子数
使粒子系统与汽车更贴切
挂载函数
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class myControl : MonoBehaviour {
public GameObject smokel;
public GameObject smoker;
public GameObject broke;
public GameObject firel;
public GameObject firer;
bool running = false;
Rigidbody rig;
// Use this for initialization
void Start () {
rig = GetComponent<Rigidbody> ();
firel.GetComponent<ParticleSystem> ().Stop ();
firer.GetComponent<ParticleSystem> ().Stop ();
broke.SetActive (false);
}
// Update is called once per frame
void Update () {
float x = rig.velocity.x;
float z = rig.velocity.z;
float s = x * x + z * z;
//当速度达到一定值时,显示尾气
if (s > 5) {
smokel.SetActive (true);
smoker.SetActive (true);
} else {
smokel.SetActive (false);
smoker.SetActive (false);
}
//加速时,喷射火焰
if (Input.GetButtonDown ("Vertical")) {
if (!running) {
running = true;
firel.GetComponent<ParticleSystem> ().Play ();
firer.GetComponent<ParticleSystem> ().Play ();
}
}
if (Input.GetButtonDown ("Vertical"))
running = false;
}
}