【问题标题】:How to transform position from one object to the current player position?如何将位置从一个对象转换为当前玩家位置?
【发布时间】:2020-02-15 21:49:46
【问题描述】:

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

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

【问题讨论】:

  • 所以,在玩家位置实例化粒子
  • 怎么^^=? :=)

标签: c# unity3d collision-detection particles particle-system


【解决方案1】:

您可以做的是创建粒子对象的预制件并在脚本中引用它,如下所示:

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

【讨论】:

    【解决方案2】:

    知道了 :) --> 添加death_explosion.transform.position = GameObject.Find("player").transform.position;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多