Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将一个对象的位置转换为当前玩家的位置?_C#_Unity3d_Collision Detection_Particles_Particle System - Fatal编程技术网

C# 如何将一个对象的位置转换为当前玩家的位置?

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

我的玩家身上有一个小粒子系统,如果他死了,他会爆炸。但是我不能简单地将particlesystem附加到播放器下,因为如果我销毁了我的播放器,那么游戏对象的孩子也会被销毁。如果他死了,动画就会播放,但不是在他现在的位置,那么有什么想法吗?也许是在玩家死后将其位置转换为当前位置? 这是我的代码:

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);
        }
    }

因此,在播放器位置实例化粒子,并说明如何^^=?:=)