- Home /
Trouble with java raycast scripts to open a door
I have been following a tutorial that i found on the internet on how to use Unity and right now i am learning raycasthit to open doors. well i followed the script that the guy wrote and it still won't work. this is the code that i am using
var rayCastLength = 5;
function update() { var hit : RaycastHit;
//Check if we're colliding
if(Physics.Raycast (transform.position, transform.forward, hit, rayCastLength))
{
//... with the door
if(hit.collider.gameObject.tag == "door")
{
//open the door!
hit.collider.gameObject.animation.Play("door_open");
}
}
}
any help here would be welcome
Please edit your code to look right. Java is not JavaScript.
Check the door is tagged. Place a print("hit") just before the animation line to check if its a problem with the animation.
no its not a problem with the animation because when i set it to play when the player collides with the door, it works perfectly fine.
Your answer
![](https://koobas.hobune.stream/wayback/20220613134651im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Trouble with java raycast scripts to open a door 2 Answers
FPSController Collision with moving objects 2 Answers
Object gone aftar play - Animation problem. 0 Answers
Door animation after press a key 2 Answers
Animation clip does not exist? 1 Answer