我试图让布娃娃在点击时打开,但我不知道该怎么做。我已经有了布娃娃,但打开布娃娃的脚本不起作用。
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;
}
}