Hello and Moin moin,
i made a crate prefab with a script to open the crate with an animation.
My problem is when i have more prefabs in my scene and i open one crate that all other crates open too.
How can i seperate the prefabs than only the Crate opend that i cilck?
My Game is a First Person Game an my prefab has an animation and two collider, one collider as physic collider and on as trigger.
here is my code and thanks for your help.
public class OpenCrateWithAnim : MonoBehaviour
{
private Animator animator;
private void Awake()
{
animator = GetComponentInChildren<Animator>();
}
private void OnTriggerStay(Collider other)
{
if (Input.GetKeyDown(KeyCode.F) && !animator.GetBool("isOpend"))
{
OpenCrate();
//DropItems();
Debug.Log("crate opend");
Destroy(gameObject, 20);
}
}
private void OpenCrate()
{
animator.SetBool("isOpend", true);
}
}

