- Home /
Question by
KUFgoddess · Nov 17, 2018 at 12:19 PM ·
script.openinglooting
How to open 1 treasure chest at a time using Animator / Mechanim
Hello I'm trying to open 1 treasure chest at a time. Currently all of the treasure chests in the game open when i'm only trying to open 1 at a time using animator / mechanim and a bool.
Here's what I've got so far.
if (Input.GetKeyDown(KeyCode.E))
{
ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit, distance))
{
this._animator.SetBool("open", true);
StartCoroutine("GiveItems");
StopCoroutine("GiveItems");
}
}
Comment
Best Answer
Answer by KUFgoddess · Nov 18, 2018 at 07:23 PM
figured it out!
if (Physics.Raycast(ray, out hit, distance) && hit.transform.IsChildOf(this.transform))
instead of
if (Physics.Raycast(ray, out hit, distance))
Your answer
![](https://koobas.hobune.stream/wayback/20220612182253im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Door Script compiler error 0 Answers
Question about moving an object technique 3 Answers
jumping from ledge problem 1 Answer
Animator into OnCollisionEnter 0 Answers
Make a slider into a gauge with variables from script? 0 Answers