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 RandomGuy · Jul 11, 2013 at 01:09 AM · scriping

Can't reactivate object

Ok, so I made a Torch in my game that I want you to be able to put away and bring back at will. It has to be deactivated so its light quits shining too. It goes away fine, but when I press the button to bring it back the animation will play but it doesn't reactivate. The object does have children. I think I might have something wrong with my script because I'm brand new to scripting. This is my scrip so far. I have the script on a parent object "melee" so the script wouldn't get deactivated along with the rest of the object. The two functions at the end are set as events in the animations. If you guys can help me out that'd be great.

 #pragma strict
 
 var Torch : GameObject;
 
 function Start ()
 {
 Torch = GameObject.Find("player/Main Camera/melee/Torch");
 }
 
 function Update ()
 {
     if(Input.GetKeyDown(KeyCode.T))
     {
         Torch.animation.CrossFade("TorchAway");
     }
     if(Input.GetKeyDown(KeyCode.Y))
     {
         Torch.animation.CrossFade("TorchReturn");
     }
 }
 function TorchAway ()
 {
     Torch.SetActive(false);
 }
 function TorchReturn ()
 {
     Torch.SetActive(true);
 }
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 kbabilinski · Jul 11, 2013 at 05:05 AM 0
Share

does the object stay in the inspector when it is false ?

avatar image Benproductions1 · Jul 11, 2013 at 05:50 AM 0
Share

How are you calling TorchReturn?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TonyLi · Jul 11, 2013 at 01:14 PM

Since Torch is inactive, this line won't run:

      Torch.animation.CrossFade("TorchReturn");

Instead, try this:

     if(Input.GetKeyDown(KeyCode.Y))
     {
         Torch.SetActive(true);
         Torch.animation.CrossFade("TorchReturn");
     }

If the TorchAway animation has played, I'm guessing it has faded out the torch somehow. So when you activate it on KeyCode.Y, it should basically be invisible until TorchReturn finishes playing.

If that doesn't work, you could get more complicated and disable the torch's MeshRenderer until TorchReturn() gets called.

Comment
Add comment · Show 1 · 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 RandomGuy · Jul 11, 2013 at 03:50 PM 0
Share

That worked perfectly! Thanks for the help.

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

18 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody help 0 Answers

Error BCE0019 1 Answer

Player using turret problem 1 Answer

Invalid SceneHandle 0 Answers

How to add OnClick listener in script to see it in inspector? 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