当前位置:网站首页>unity3d粒子碰撞检测,判断例子碰撞到物体
unity3d粒子碰撞检测,判断例子碰撞到物体
2022-08-07 10:01:00 【云小川】
1.首先 物体必须有Collder
2.把特效的Particle System 中的Collision组件里的Send Collision Messages 的对勾打上,才能使函数生效.
脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeXiaoPengZhuang : MonoBehaviour
{
private ParticleSystem m_ParticleSystem;
private void Start()
{
m_ParticleSystem = GetComponent<ParticleSystem>();
}
private void OnParticleCollision(GameObject other)
{
Debug.Log("碰撞到了other="+ other.name);
if (other.tag == "tt")
{
Debug.Log("碰撞到了tt");
}
}
}
3.还可以利用ParticleCollisionEvent数组来处理多个粒子对象碰撞事件事件
官方案例(手动在Scene 面板拖动特效或者物体,使他们相碰撞,即可触发OnParticleCollision 函数)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TeXiaoPengZhuang : MonoBehaviour
{
public ParticleSystem part;
public List<ParticleCollisionEvent> collisionEvents;
private void Start()
{
part = GetComponent<ParticleSystem>();
collisionEvents = new List<ParticleCollisionEvent>();
}
private void OnParticleCollision(GameObject other)
{
int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
Rigidbody rb = other.GetComponent<Rigidbody>();
int i = 0;
while (i < numCollisionEvents)
{
if (rb)
{
Vector3 pos = collisionEvents[i].intersection;
Vector3 force = collisionEvents[i].velocity * 10;
rb.AddForce(force);
}
i++;
}
}
}
边栏推荐
- 为什么我要说:柯里化 == 闭包+递归?
- [.NET6+Modbus] Modbus TCP protocol analysis, simulation environment and basic communication based on .NET
- Mastering Andriod Reverse in 100 Days - Day 1: ADB Principles and Common Commands
- LeetCode [206. Reverse linked list] (1)
- Knowledge of Node
- VPC5021电流模式 PWM 控制器 3uA 超低启动电流
- What skills does a technical director need?priority?
- 2022 Niuxue Multi-School League Game 6 Solution
- UGUI系列-鼠标移动到按钮上显示信息(Unity3D)
- YOLOV5学习笔记(六)——优化网络架构
猜你喜欢

Flask框架——应用错误处理

大厂外包,值得拥有吗?

360 Enterprise Security Cloud debuts at the 2022 Global Digital Economy Conference to consolidate the digital foundation of small, medium and micro enterprises

(一)UPF之电源网络(Supply_port、Supply_net、Supply_set)

The snowflakes algorithm of a database table

leetcode 27. 移除元素

The 900-page mathematical paper proves that the rotating black hole will not explode, Chengtong Yau: The first major breakthrough in general relativity in more than 30 years...

数据库分表之雪花算法
![[Flash programming of Autosar memory stack Memory Stack 4.Tc397]](/img/69/a562a7803e46bc5fb4607a1b13471b.png)
[Flash programming of Autosar memory stack Memory Stack 4.Tc397]

Unity 3D game general system settings page, custom key settings, background blur, image settings, brightness, contrast, saturation, volume adjustment, resolution windowing, frame rate vertical sync, a
随机推荐
项目优化之光照使用(Unity3D)
求平均数解决溢出问题的方法
[Bit band operation to register assignment] GPIO multiplexing mode initialization based on ADuCM4050
The principle and source code of redis - transaction mechanism
MASA Stack 第三期社区例会
简化理解:发布订阅
这种调试方法,你值得拥有
Some summary about common build tools
如何仿造websocket请求?
Node的知识理解
Automatic processing software for geometric data topology errors based on FME
技术总监需要具备哪些能力?优先级?
For high-performance, ultra-large-scale model training, this combination "debuts"
产品“白送”+溢价入股,赛诺菲打响抄底中国生物科技资产第一枪
ABP 6.0.0-rc.1的新特性
What skills does a technical director need?priority?
在Inspector面板中显示变量和类(Unity3D)
UGUI系列-文字实现进度等待、进度加载、进程等待演示动画
unipush2.0教程
The principle and source code of redis - the principle and source code analysis of cluster (on)