c# - 向与粒子系统 C# 交互的对象添加力
问题描述
我目前有一个粒子系统,应该代表吹叶机。我已经让这个工作在鼠标点击时开启和关闭。
问题是,我希望它像逼真的吹叶机一样“吹”出物体。我听说有些人喜欢使用 AddForceAtPosition 或类似的东西,只是我不知道如何使用它。
目前,当我的“吹叶机”打开时,我正在启用和禁用一个盒子对撞机,并且让对撞机触摸的所有东西都被击退,但这证明在游戏中存在各种问题。
这是我正在使用的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class leafblower : MonoBehaviour {
private Rigidbody rb;
protected bool letPlay;
public ParticleSystem blow;
public Collider lcol;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
blow = GetComponent<ParticleSystem>();
lcol.enabled = !lcol.enabled;
}
void LeafBlower()
{
if (Input.GetKeyDown(KeyCode.Mouse1))
{
var isBlowing = blow.emission;
isBlowing.enabled = true;
lcol.enabled = !lcol.enabled;
}
else if (Input.GetKeyUp(KeyCode.Mouse1))
{
var isBlowing = blow.emission;
isBlowing.enabled = false;
lcol.enabled = !lcol.enabled;
}
}
// Update is called once per frame
void Update()
{
LeafBlower();
}
void FixedUpdate()
{
}
}
我应该添加什么力量,或者我应该在 void OnCollisionEnter() 中添加什么?太感谢了 :)
解决方案
您可能需要的是粒子系统碰撞OnParticleCollision
。请在此处查看 Unity 脚本 API:https ://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html
推荐阅读
- mysql - 使用 Dockerfile 在 CentOS 7 上安装 MySQL 失败
- python - “时间戳”类型的参数不可迭代?
- python - 如何让 matplotlib 实际更新到最新版本?
- python - 尝试在 Lambda 函数中运行 ansible - 无法使依赖项达到可接受的上传大小
- javascript - Javascript:在 Reduce 函数中无法理解空初始化器
- r - 循环遍历数据表列并使用 for 循环应用 glm
- mongodb - 更好的方法创建 estructure 集合 mongodb,更新并插入子文档
- ios - 数据在 CollectionView 单元格中未正确显示?
- c# - Foreach 循环遍历字典导致 StackOverflowException
- python-3.x - 形状力图不显示图:shap.plots._force.AdditiveForceVisualizer