0

我试图让布娃娃在点击时打开,但我不知道该怎么做。我已经有了布娃娃,但打开布娃娃的脚本不起作用。

using System.Collections;

使用 System.Collections.Generic;使用 UnityEngine;

公共类 RagdollEnemy : MonoBehaviour {

// Start is called before the first frame update
void Start()
{
    setRigidbodyState(true);
    setColliderState(false);
    GetComponent<Animator>().enabled = true;
}

public void die()
{

    GetComponent<Animator>().enabled = false;
    setRigidbodyState(false);
    setColliderState(true);

    if (gameObject != null)
    {
        Destroy(gameObject, 3f);
    }

}

void setRigidbodyState(bool state)
{

    Rigidbody[] rigidbodies = GetComponentsInChildren<Rigidbody>();

    foreach (Rigidbody rigidbody in rigidbodies)
    {
        rigidbody.isKinematic = state;
    }

    GetComponent<Rigidbody>().isKinematic = !state;

}


void setColliderState(bool state)
{

    Collider[] colliders = GetComponentsInChildren<Collider>();

    foreach (Collider collider in colliders)
    {
        collider.enabled = state;
    }

    GetComponent<Collider>().enabled = !state;

}

}

4

1 回答 1

0

这可能不是正确的方法,但是,您可以将 ragdoll 游戏对象用作另一个游戏对象,当您死时设置为活动状态,并将位置设置为玩家位置并将活动设置为假您的玩家。我在游戏中将它用于我的角色和敌人人物。

于 2020-05-19T15:01:08.017 回答