Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Mightycam · Jan 02, 2015 at 06:50 AM · animationraycastanimatorraycasthit

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);
     
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Umresh · Jan 02, 2015 at 11:37 AM 0
Share

I didn't get you. Do you want to play all the animations one after another after mouse click?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mightycam · Jan 03, 2015 at 10:08 AM 0
Share

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?

avatar image Mightycam · Jan 03, 2015 at 11:19 AM 0
Share

is it possible to make an array to the raycast script to connect all the animators into one?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Play Animation on Raycast *open and close some objects* 0 Answers

Trying to play other objects' sound and animations from Raycast hit 1 Answer

Door only opening once on Raycast 1 Answer

Animation on Raycast Not Playing 1 Answer

2D Animation does not start 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges