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 RichCoggin · Apr 15, 2013 at 07:25 PM · animationcolliderdestroy

Play animation before death...c#

Hi there,

I'm trying to activate an animation which is associated with an object. When the Object hits the collider 'Destroy', the object is killed fine, but the animation doesn't play before this. Can you help to work out how this can happen. I have the animations in the object set up and is hitting an object with a trigger selected.

 void OnTriggerEnter(Collider other) {
 if (other.tag == "Destroy")
            {
            _GameManager.GetComponent<GameManager>().Death();
            Destroy(GameObject.FindWithTag("JackSteelBody"),4);
            Jack.GetComponent().Play ("JackBreak");
            }

The error that comes up is:

 Assets/Script/Player/PlayerControl.cs(81,25): error CS0103: The name `Jack' does not exist in the current context

Many thanks for any help.

Rich

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by GluedBrain · Apr 15, 2013 at 08:40 PM

Well, since you're destroying the gameobject first and then playing the animation i.e.

  Jack.GetComponent().Play ("JackBreak");

comes after it has been destroyed. SO there's no JACK anymore. Try attaching the animation to a different gameobject of the same kind which will be instantiated after the JACK dies.

Comment
Add comment · Show 4 · 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 RichCoggin · Apr 15, 2013 at 09:19 PM 0
Share

Thanks. That works. I did think though that I put a wait on the Destroy for 4 seconds. Would that not do it?

avatar image FWCorey · Apr 15, 2013 at 10:13 PM 0
Share

If you do it in a coroutine it will, but since it's just a function it waits until it's finished before going to the next line. I also suggest ins$$anonymous$$d of using a fixed delay, have your coroutine wait the “.Length” of the animation so if it gets changed later you won't have to edit the code.

avatar image GluedBrain · Apr 18, 2013 at 04:47 PM 0
Share

I'm late but, did that clear your doubt?

avatar image RichCoggin · Apr 18, 2013 at 09:35 PM 0
Share

I have been down a long and dark road and have come out the other side to find a few other challenges. I am now now watching The Lord Of The Rings which journey I am beginning to relate to. Thanks for your help. It went some way, but only part of the puzzle. As with all these projects there are many pieces to place.

S$$anonymous$$ling the words: Hobbits! [cheers abound.] "I don't know half of you half as well as I should like, and I like less than half of you half as well as you deserve."

Rich

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

13 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

Related Questions

Destroying object when player walks over it 1 Answer

Trigger Animation doesn't work, please help me. 1 Answer

Destroy trigger so animation only plays once. 1 Answer

Make mesh collider constantly change 1 Answer

Animation messes up if GameObject is destroyed 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