作业要求
简单粒子制作
1、按参考资源要求,制作一个粒子系统
2、用代码控制使之在不同场景下效果不一样
作业内容
制作粒子系统
粒子系统包含核心、光晕、星光三个部分,这三个部分的制作方法是相同的,只是修改了相关的参数。
制作粒子系统:点击场景右键,点击游戏对象,点击效果,便可以创建粒子系统。
下面是不同部分的相关数据:
起始颜色为黄色。
其他部分按自己喜欢进行更改。
效果图:
用代码控制粒子系统的效果
对系统使用脚本控制大小。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class sizechanged : MonoBehaviour
{
ParticleSystem changed;
float size = 9f;
float p = 1f;
// Start is called before the first frame update
void Start()
{
changed = GetComponent<ParticleSystem>();
}
void OnGUI()
{
if (GUI.Button(new Rect(200, 275, 100, 50), "变小"))
{
p = 0.999f;
Update();
}
if (GUI.Button(new Rect(350, 275, 100, 50), "变大"))
{
p = 1.001f;
Update();
}
/*size = 0.999f * size;
var main = changed.main;
main.startSize = size;*/
}
private void Update()
{
size = p * size;
var main = changed.main;
main.startSize = size;
}
}
使用按钮来控制操作。
同样使用脚本来控制系统颜色:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class colorchanged : MonoBehaviour
{
ParticleSystem changed;
// Start is called before the first frame update
void Start()
{
changed = GetComponent<ParticleSystem>();
}
void OnGUI()
{
if (GUI.Button(new Rect(150, 25, 100, 50), "变红"))
{
changed.startColor = new Color(255f, 0f, 0f);
}
if (GUI.Button(new Rect(275, 25, 100, 50), "变蓝"))
{
changed.startColor = new Color(0f, 0f, 255f);
}
if (GUI.Button(new Rect(400, 25, 100, 50), "变绿"))
{
changed.startColor = new Color(0f, 255f, 0f);
}
}
}
使用下面代码来改变颜色:
changed.startColor = new Color(0f, 0f, 0f);
效果视频:
粒子系统