我目前有一个应该代表吹叶机的粒子系统。我有这个工作来点击鼠标点击开关。
问题是,我希望它像一个真实的吹叶机一样“吹”出物体。我听说有些人喜欢使用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 Scripting API:https://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html