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 dkenne38 · Nov 29, 2012 at 05:34 PM · deathdie

Character disappears when dies.

My character just disappears when he dies, i was wondering how to play the "die animation" when he dies instead of just disappearing?

Any help would be fab thanks! :)

The code i have is:

 function OnTriggerEnter (other : Collider) {
 
 
   Destroy(other.gameObject);
   animation.Play("die");
   
 }
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Dave-Carlile · Nov 29, 2012 at 05:43 PM

It's disappearing because you're destroying it. Remove the Destroy call.

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 dkenne38 · Nov 29, 2012 at 05:47 PM 0
Share

but it doesn't die with out it? i don't have a clue how else to get it to die (i know that sounds stupid but i've never used this program before :/)

avatar image MibZ · Nov 29, 2012 at 06:37 PM 2
Share

Destroy() will delete whatever object you give it, the line 'animation.Play("die");' is never reached.

There are several ways you could do what you want. You could either add a variable like 'bool alive' that is true when the player is alive, and only let the person playing the game control the character when it is alive.

Update() { if (alive) { //Put your controls/code to run while character is alive here } else if (alive == false) { animation.Play("die"); }

Or you could make another version of you player that only has a death animation on it with no player script and when your player dies spawn the deathAnimationPlayer where your Player was and then destroy your player.

You would make a small script for the deathAnimationPlayer that would only need 'animation.Play("die");' in the Start() function.

function OnTriggerEnter (other : Collider) { GameObject temp = Instantiate(deathAnimationPrefab, gameObject.transform.position, gameObject.transform.rotation); Destroy(other.gameObject); }

avatar image
0

Answer by Chronos-L · Nov 30, 2012 at 08:55 AM

If you want your object disappear after the animation, modify your code to:

`function OnTriggerEnter (other : Collider) {`

   animation.Play("die");
 
 }
 
 private void Kill() {
   //Destroy your player or whatever you
   //want to happen at the end of your animation
 }

You can then attach Kill() in the end of the [die] animation via animation event

And the Kill() function will be called in the end of the animation (or at the frame you have assigned the function to)

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 dkenne38 · Nov 30, 2012 at 03:59 PM 0
Share

Thanks, i tried to get this to work but i don't really have a clue how to add that animation event thing :/ (literally barely know how to do anything properly on unity haha)

avatar image
0

Answer by Maulik2208 · Nov 30, 2012 at 01:00 PM

I think you should use Destroy(other.Gameobject,10); this code will destroy your gameobject after 10 sec so in that 10 sec you play the animation.Play("Die"); for better visualization you can use your animation time's lenght +1 or +2 sec.......means if the animation is of 10 sec then destroy at 12......by using Destroy(other.Gameobject,12);.......Here 12 represent time in sec to wait before destroy the object Hope This will work for you........Enjoy

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 dkenne38 · Nov 30, 2012 at 03:54 PM 0
Share

Like this?:

function OnTriggerEnter (other : Collider) {

Destroy(other.gameObject,5); animation.Play("die"+3);

}

The delay seems to be working, but the animation still isn't playing before the character disappears?

avatar image MibZ · Nov 30, 2012 at 04:29 PM 0
Share

Is it a problem with the animation itself? If you comment out the Destroy function call does the animation play?

(In case you don't know, you can comment out a line by adding '//' at the beginning and the compiler won't read any code from that line, good for documenting what does what and temporarily removing code)

avatar image dkenne38 · Nov 30, 2012 at 04:39 PM 0
Share

The animation seems to work, but it doesnt fully play. when the character bumps in the cube (the trigger that will kill the character) the animation starts to play, but then just stops the character will stand normally and then die after the 10seconds.

Yeah i've been commenting stuff. (this is the first time i've ever wrote code for a game so i'm pretty hopeless at getting anything to work properly haha)

avatar image MibZ · Nov 30, 2012 at 04:52 PM 0
Share

In that case when you split the animation into clips you may not have given it every frame. Look at the animation file and make sure the frame numbers line up to the clip frame numbers

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

14 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

Related Questions

Death on impact with water 1 Answer

AI Awareness 2 Answers

Death script problem 2 Answers

Scene not restarting after player death 2 Answers

How to make death messages show at random? 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