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 defterniko · Nov 22, 2012 at 01:37 PM · c#animationtrigger

play only one door animation

Hi folks,

I am current;y building a scene where the player is in a ship, in the ship as you would assume there are doors and the players open them by clicking 'o' on a control panel...the door animation will then play, so the door is open.

The problem is, when I play the animation for some reason it opens every door as oppose to the one the control panel is connected to through scripts.

I have one script connected to the control panel and one connected to the door. In the control panel script it checks to see if the player has pressed O and if they do it sends a message to the door connected to this script, at the start called triggeringObject,

 if (Input.GetKeyDown (KeyCode.O))
             {
             if (activated == true)
                 {
                     activated = false;
                 }
             else
                 {
                     activated = true;
                 }
             }
 
 if (activated == true)
         {
             triggeringObject.SendMessage("TurnOn");
         }
         else
         {
             triggeringObject.SendMessage("TurnOff");    
         }

In the doors trigger object script I have to functions one to turn on and one to turn off.

 void TurnOn()
     {
         //this.transform.renderer.material.color = new Color(0,255,0,255);
          
         
         this.transform.animation.wrapMode = WrapMode.ClampForever;
         this.transform.animation.Play("Take 001");
         
         
     }
     
     void TurnOff()
     {
         //this.transform.renderer.material.color = new Color(255,0,0,255);    
         
         
         this.transform.animation.Rewind();
     }

as you can see I tell it trigger the animation of that door, yet every door gets played. Any Ideas?

Thanks in advanced

Comment
Add comment · Show 2
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 SteveFSP · Nov 22, 2012 at 04:09 PM 0
Share

A question: In what function is first code snippet you show located?

avatar image defterniko · Nov 22, 2012 at 04:27 PM 0
Share

it's in the Update function

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by SteveFSP · Nov 22, 2012 at 05:04 PM

I don't see how you are filtering what is receiving the key down. If key detection is occurring in the update function of each control panel, then all control panels are detecting the key down and sending out the message to all doors. E.g. 3 control panels have the script attached, 3 will detect the key down and send out the message to 3 doors.

A common technique is to put the key detection into an input control script on a single object such as the player, then use a ray cast to decide which object is receiving the command.

A simple example:

In the central input control's update function:

 If key down 'o'
     Raycast to center of screen.
     If hit object is a control panel
         Call the ToggleDoor() method on the control panel.

Reference: Ray casting to center of screen.

The key issue is that you have to make sure that only one control panel is responding to the key down.

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 defterniko · Nov 22, 2012 at 05:37 PM 0
Share

thanks for reply i'll give that a shot.

avatar image defterniko · Nov 22, 2012 at 08:41 PM 0
Share

It worked thanks very much

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NetworkAnimator: SetBool vs. SetTrigget? 1 Answer

Anisprite animation from OnTriggerEnter 0 Answers

Is there a function that will return the current frame of an animation? 1 Answer

Triggering animation on click when a key is collected 1 Answer

How to override an animation? 0 Answers


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