Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by ccorgis · Feb 12, 2016 at 09:52 PM · collision detectioncollider2ddestroy objectendgamekill player

How to kill player (and or end game) when enemy hits the ground? JAVASCRIPT

I have this game where my player is a hat and you catch the bombs and don't let them fall to the ground, like you're protecting it or something like that.

Anyway, seeing as the whole point in the game is to keep the bombs from touching the ground, I need a script where the player is killed and or the game ends when a bomb hits the ground. I've tried/looked up everything, but I can't seem to find a code/code this stupid script myself. Please help!

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
0

Answer by dan5071 · Feb 14, 2016 at 01:05 AM

How exactly do you define the game ending or the player being killed? Is the player game object destroyed? Does a menu pop up? Whatever the logic behind those things happening might be, one way you could approach the problem is to setup a collider on the ground and do collision detection through OnCollisionEnter(). When you detect a collision with the ground, you perform the necessary actions to end the game. Note that this will require all of your bombs to have (presumably) sphere or circle colliders in addition to the ground. Here are some good resources for learning more:

http://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html

http://unity3d.com/learn/tutorials/modules/beginner/physics/on-collision-enter

An alternative option would be to use the Update routine to detect whether or not each bomb's y position is below a certain height (i.e., the y position of the ground). If so, destroy the player game object, instantiate your replay menu, and do whatever else you might need to do. Note that this will require either each of your bombs to be running the update routine in the scripts attached to each individual object, or to run a single script that searches for all bombs in the scene and detects if their y position at ground level.

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

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

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

Related Questions

Destry object on collision with 'bullet' 0 Answers

Question about coll.contacts 1 Answer

Collider Issue 0 Answers

help with colliders not working 2 Answers

Hit from kinematic rigidbody2d 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