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 /
This question was closed Jan 26, 2019 at 08:50 PM by dARkStorN- for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by dARkStorN- · Jan 26, 2019 at 05:45 PM · player movementmenu screenendgame

My Death() method is working on collusion but fails to get deathMenu when i fall.

Good evening Unity folks. It is my first post here and I started studying Unity a month ago, therefore if this question seems stupid to you i apologize for it beforehand.

I have basically 3 scripts working and i followed N3K's Endless Runner tutorial on YouTube. The first script is PlayerMotor and calls the OnDeath method of PlayerScore script when our controller hits an obstacle. OnDeath method of PlayerScore script calls the ToggleEndMenu method of DeathMenu script which sets active the DeathMenu gameobject with the score we have on death.

PlayerMotor script:

 void Update()
 {
       if (transform.position.y < -1)
         {
             Death();
         }
 }
 private void OnControllerColliderHit(ControllerColliderHit hit)
     {
         if (hit.point.z > transform.position.z + 0.1f && hit.gameObject.tag == "Enemy")
         {
             Death();
         }
     }
 
     private void Death()
     {
         isDead = true;
         GetComponent<PlayerScore>().OnDeath();
     }

PlayerScore script:

 public void OnDeath()
     {
         isDead = true;
 
         if (PlayerPrefs.GetFloat("Highscore") < score)
         PlayerPrefs.SetFloat("Highscore", score);
 
         deathMenu.ToggleEndMenu(score);
     }

DeathMenu script:

 public void ToggleEndMenu(float score)
     {
         gameObject.SetActive(true);
         scoreText.text = ((int)score).ToString();
         isShown = true;
     }

So my problem is when i hit an obstacle Death() method works perfectly fine and my death menu pops up with my score immediately. However when my character falls from a bridge or something my Death() method in Update class stops the score counter on screen but doesnt set active DeathMenu gameobject so my death menu doesnt pop on my screen. I'm really confused why it doesnt work. Can someone help me with this?
Note: I deleted unrelated lines of codes from my scripts.

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

2 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by dARkStorN- · Jan 26, 2019 at 07:56 PM

I added a box collider under my all re-instantiated prefabs and added this line of code to my PlayerMotor and it works like a charm. Thanks @Ymrasu for the hint!

 private void OnControllerColliderHit(ControllerColliderHit hit)
     {
         if (hit.point.z > transform.position.z + 0.1f && hit.gameObject.tag == "Enemy")
         {
             Death();
         }
         if (hit.point.y < transform.position.y + 0.5f && hit.gameObject.tag == "Enemy")
         {
             Death();
         }
     }
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
avatar image
1

Answer by Ymrasu · Jan 26, 2019 at 06:59 PM

Instead of checking if the player is beyond a certain y point, I would put a long box collider under your world set up similar to the other obstacles that are working. That way if the player falls, they would hit the obstacle under your world and call your OnDeath that way.

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 dARkStorN- · Jan 26, 2019 at 07:38 PM 0
Share

I thought the same thing but because it is an endless runner shouldn't my box collider has an infinite scale to achieve the result in every frame possible. What if i destroy the colliders on my past and re-instantiate it under the tiles that i am about to run. Would it be more efficient in terms of memory usage?

Follow this Question

Answers Answers and Comments

99 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 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 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

How do I destroy my player on contact? 2 Answers

Player jitters when moving. 1 Answer

Unity 2D: Properly Implementing Player Movement with a dash, jump, and knockback? 2 Answers

Game Object Scaling based on Proximity 1 Answer

Unity input system character control 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