1 Star 0 Fork 0

lhylhy / UnityGameHomework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
SController.cs 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
lhylhy 提交于 2020-12-02 16:36 . lizi
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SController : MonoBehaviour
{
public ParticleSystem ps;
public ParticleSystem.Particle[] particles;
public int speed=5;
public float k=0.05f;
public float b=1;
public Transform tr;
void Start()
{
ps=gameObject.GetComponent<ParticleSystem>();
particles=new ParticleSystem.Particle[ps.maxParticles];
tr.position=new Vector3(0,0,0);
}
// Update is called once per frame
void FixedUpdate()
{
int num=ps.GetParticles(particles);
float x,y,z;
float r,nowr,rate;
for (int i=0;i<num;++i){
Vector3 v=particles[i].position;
x=v.x;
y=v.y;
z=v.z;
nowr=(new Vector3(0,y,0)-particles[i].position).magnitude;
r=y*y*k+b;
if (nowr<=0.5){
x=1;
z=0;
}else{
rate=r/nowr;
x=x*rate;
z=z*rate;
}
tr.position=new Vector3(x,y,z);
tr.RotateAround(new Vector3(0,y,0),Vector3.up,speed);
particles[i].position=tr.position;
}
ps.SetParticles(particles,num);
}
}
C#
1
https://gitee.com/lhyyes/unity-game-homework.git
git@gitee.com:lhyyes/unity-game-homework.git
lhyyes
unity-game-homework
UnityGameHomework
master

搜索帮助