C# 如何将一个对象的位置转换为当前玩家的位置?
我的玩家身上有一个小粒子系统,如果他死了,他会爆炸。但是我不能简单地将particlesystem附加到播放器下,因为如果我销毁了我的播放器,那么游戏对象的孩子也会被销毁。如果他死了,动画就会播放,但不是在他现在的位置,那么有什么想法吗?也许是在玩家死后将其位置转换为当前位置? 这是我的代码:C# 如何将一个对象的位置转换为当前玩家的位置?,c#,unity3d,collision-detection,particles,particle-system,C#,Unity3d,Collision Detection,Particles,Particle System,我的玩家身上有一个小粒子系统,如果他死了,他会爆炸。但是我不能简单地将particlesystem附加到播放器下,因为如果我销毁了我的播放器,那么游戏对象的孩子也会被销毁。如果他死了,动画就会播放,但不是在他现在的位置,那么有什么想法吗?也许是在玩家死后将其位置转换为当前位置? 这是我的代码: using System.Collections; using System.Collections.Generic; using UnityEngine; public class playerdea
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();
}
}
明白了:)-->add
death\u explosion.transform.position=GameObject.Find(“玩家”).transform.position代码>您可以创建粒子对象的预设,并在脚本中引用它,如下所示:
public ParticleSystem death_explosion_Prefab;
并在碰撞时实例化它,而不是将其作为子对象附加到播放器:
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "deathcube")
{
Debug.Log("collision detected");
Instantiate(death_explosion_Prefab, gameObject.transform.position, Quaternion.identity);
Destroy(gameObject);
}
}
因此,在播放器位置实例化粒子,并说明如何^^=?:=)