c# - 如何将位置从一个对象转换为当前玩家位置?
问题描述
所以我在我的播放器上安装了这个小粒子系统,所以如果他死了,他就会爆炸。但我不能简单地将粒子系统附加到玩家下方,因为如果我摧毁我的玩家,游戏对象的孩子也会被摧毁。如果他死了,动画就会运行,但不是在他现在的位置,所以有什么想法吗?也许在玩家死亡时将位置转换为玩家的当前位置?这是我的代码:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerdeath : MonoBehaviour
{
public ParticleSystem death_explosion;
// Start is called before the first frame update
void Start()
{
death_explosion.Stop();
}
// Update is called once per frame
void Update()
{
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "deathcube")
Destroy(gameObject);
Debug.Log("collision detected");
death_explosion.Play();
}
}
解决方案
您可以做的是创建粒子对象的预制件并在脚本中引用它,如下所示:
public ParticleSystem death_explosion_Prefab;
而不是将它作为孩子附加到 Player 上,而是在碰撞时实例化它:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "deathcube")
{
Debug.Log("collision detected");
Instantiate(death_explosion_Prefab, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
推荐阅读
- java - 尝试将片段添加到项目时,我的应用程序崩溃
- capl - CAPL中如何实现线程阻塞
- mysql - 我想在 mySQL 中运行我的脚本,但是在我运行它时它一直显示这个!!!第 18 行的错误 1215 (HY000):无法添加外键约束
- android - 在android studio中同步失败
- android - 反应原生 android 版本 0.57
- oracle - 如何创建检查 vlue 是否低于产品的 reorder_point 属性的更新语句
- android - 在创建用户firebase android之前检查电子邮件是否存在
- ros - 我怎样才能摆脱错误:找不到包'turtlebot_gazebo'?
- corda - 节点可以在没有状态 cordapp 的情况下签署交易吗?
- python - Matplotlib 压缩 Y-Ticks 很有用