向与粒子系统 C# 交互的对象添加力
Adding force to objects that interact with a particle system C#
我目前有一个粒子系统,应该代表吹叶机。我已经让这个工作在鼠标点击时打开和关闭。
问题是,我希望它像逼真的吹叶机一样 "blow" 对象。我听说有些人喜欢用AddForceAtPosition之类的,只是我不知道怎么用。
目前,当我的 'leafblower' 开启时,我正在启用和禁用一个盒子碰撞器,并让碰撞器接触到的所有东西都被击退,但这被证明在游戏中存在各种问题。
这是我正在使用的代码:
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
我目前有一个粒子系统,应该代表吹叶机。我已经让这个工作在鼠标点击时打开和关闭。
问题是,我希望它像逼真的吹叶机一样 "blow" 对象。我听说有些人喜欢用AddForceAtPosition之类的,只是我不知道怎么用。
目前,当我的 'leafblower' 开启时,我正在启用和禁用一个盒子碰撞器,并让碰撞器接触到的所有东西都被击退,但这被证明在游戏中存在各种问题。
这是我正在使用的代码:
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