- Home /
Raycasting Door Animator
Hey guys just a little stuck with animator. I have this raycasting script to open doors on a mouse click with animations through animator(if that makes sense). I have made four animation with four transitions inside the animator so it goes Door Closed > Door Opening > Door Open > Door Closing. So it all connects together. I've tried playing with the parameters but nothing is working and I have named the parameter the same as in the script. What kind of parameter do I choose and do I have to change anything around. I have tried bool, into and float and I've tried playing around with the greater and lower part but just can't get it working?
Here's the script below:
using UnityEngine;
using System.Collections;
public class DoorRaycast : MonoBehaviour
{
public Animator anim;
void Update()
{
RaycastHit hit;
Vector3 fwd = transform.TransformDirection (Vector3.forward);
if (Physics.Raycast(transform.position, fwd, out hit, 10))
{
if (Input.GetMouseButtonDown(0)&& hit.collider.tag=="DOOR")
{
anim.SetTrigger("DoorOPEN");
audio.Play();
}
}
/*{
anim.SetTrigger("DoorCLOSE");
audio.Play();
}*/
Debug.DrawRay (transform.position,fwd,Color.green);
}
}
I didn't get you. Do you want to play all the animations one after another after mouse click?
Answer by Krizzen · Jan 02, 2015 at 12:57 PM
I'd start with the good ol' dummy check (i.e. is it plugged in?)
Select the AnimatorController, goto the Animator window and double check that you have added a DoorOPEN parameter.
Next, click the transition (the arrow on the graph layout pointing from DoorCLOSE) and make sure you added a condition DoorOPEN.
Note that you can right-click one of the states, like DoorCLOSE and set it as the default state.
Got that all sorted out thanks a lot guys. Quick question, if I make it a prefab with the animator connected to the door will the raycast activate each animation when I click on it? Because there is going to be a lot of doors in the scene? So pretty much I open one door walk into the room and there will another 3 of the same doors as prefabs. Would the raycast play each animation or do I have to edit the script?
is it possible to make an array to the raycast script to connect all the animators into one?
Your answer
![](https://koobas.hobune.stream/wayback/20220613175405im_/https://answers.unity.com/themes/thub/images/avi.jpg)