马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?注册帐号

x

前两天在专栏看到有类似的,就自己也试着写了一个很简单的效果。【新手可以看看,大神可以直接略过了】

先上效果图吧!(PS:效果图有点失真)

flower.gif (902.73 KB, 下载次数: 40)

2017-9-9 09:52 上传

是不是效果还不错?

下面介绍下步骤吧!

一、首先,在网上找到一些花朵的资源,可以用PS处理一下。

pic5.png (147.82 KB, 下载次数: 42)

2017-9-9 09:52 上传

二、那就是创建一个新的项目了。具体的参数,我直接上图了,这里就不多说了

pic4.png (126.01 KB, 下载次数: 46)

2017-9-9 09:52 上传

pic1.png (271.83 KB, 下载次数: 54)

2017-9-9 09:52 上传

pic2.png (299.72 KB, 下载次数: 33)

2017-9-9 09:52 上传

pic3.png (369.47 KB, 下载次数: 42)

2017-9-9 09:52 上传

三、接下来就是代码的部分了。

[C#] 纯文本查看 复制代码using System.Collections;

using System.Collections.Generic;

using UnityEngine;

[System.Serializable]//序列化

public struct FlowerMessage{

public GameObject flowerPrefabs;

}

public class CreateFlower : MonoBehaviour {

//预设体list,可以存放多个预设体!

public List flowerMsg;

//坐标定位,用来确定花朵生成的范围

public Vector3 spawnValues;

private float waveTimer;//波次计时器

private int waveIndex;//随机花朵

private int count;//生成的花朵数

private bool canInitFlower = true;//可以生成花朵

void Start(){

}

void Update(){

if (!canInitFlower) {

return;

}

if (canInitFlower) {

//计时器计时

waveTimer += Time.deltaTime;

if (waveTimer >= 0.5f) {

waveIndex = Random.Range (0, flowerMsg.Count);

//这里的数值可以根据画布或需求调整,也可以不定义上面的Vector3 spawnValues.

Vector3 spawnPosition = new Vector3 (Random.Range (0, spawnValues.x * 2), Random.Range (500, spawnValues.y * 2), spawnValues.z);

//Debug.Log (spawnPosition);测试生成坐标是否合适

FlowerInit (waveIndex, spawnPosition);

//当生成一朵花后,计时器归零,重新开始计时

waveTimer = 0;

//当生成花朵数大于1000时,停止落花

if (++count >= 1000)

canInitFlower = false;

}

}

}

private void FlowerInit(int index, Vector3 spawnPosition){

//生成花朵

GameObject currentFlower = Instantiate (flowerMsg [index].flowerPrefabs, spawnPosition, Quaternion.identity) as GameObject;

currentFlower.transform.SetParent (transform);

}

}

[C#] 纯文本查看 复制代码using System.Collections;

using System.Collections.Generic;

using UnityEngine;

//该脚本挂载在每个花朵的预设体身上

public class FlowerMovement : MonoBehaviour {

//每帧下落的速度

private Vector3 downVector;

//角速度

private float angularSpeed = 3f;

void Start () {

downVector = new Vector3 (0, -1, 0);

}

void Update () {

transform.position += downVector;

//以平滑的效果旋转至目标角度

transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.Euler (45f, 10f, 45f), Time.deltaTime * angularSpeed);

//当离开画布后,消失

if (transform.position.y < 0) {

Destroy (gameObject);

}

}

}

是不是很简单?希望能对大家有所帮助。下面会放上素材包和工程的。有兴趣的可以看一看。

Flower项目包.rar

(627.11 KB, 下载次数: 310)

2017-9-9 10:06 上传

点击文件名下载附件

UnityPackage包

Logo

电影级数字人,免显卡端渲染SDK,十行代码即可调用,工业级demo免费开源下载!

更多推荐