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 /
avatar image
0
Question by Mcdsnte · Mar 22, 2018 at 10:48 AM · c#fallrespawninggame overhealth-deduction

Lose health and respawn after falling

I'm making a 2d platformer and I'm looking for something like the Shantae games where instead of having lives the player to falls off cliffs and loses a heart after respawning to the stage. I have the game over and respawn system set, but the player ends up recovering lost health after the respawn as opposed to losing.

Please help!

My kill script: using UnityEngine; using System.Collections; public class KillPlayer : MonoBehaviour { public Player player; // Use this for initialization void Start () { player = FindObjectOfType<Player> (); } // Update is called once per frame void Update () { } void OnTriggerEnter2D(Collider2D other) { if (other.tag == "Player") { player.Death (); player.Damage (1); } } }

and my respawn code: public void Respawn () { StartCoroutine ("RespawnCoroutine"); } //Routine for respawn dalay time public IEnumerator RespawnCoroutine() { gamePlayer.gameObject.SetActive (false); yield return new WaitForSeconds (respawnDelay); gamePlayer.transform.position = gamePlayer.respawnPoint; gamePlayer.gameObject.SetActive (true); } }

Comment
Add comment · Show 4
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 Legend_Bacon · Mar 22, 2018 at 03:09 PM 0
Share

Hello there,

You need to provide more information if you want us to be able to help. For example, how did you setup your respawn system? Please share the relevant code as well (edit your original post) so we can have a look!

Cheers,

~LegendBacon

avatar image Mcdsnte Legend_Bacon · Mar 22, 2018 at 10:21 PM 0
Share

Sorry, I've been at work but I believe I've set it to show my methods

avatar image Legend_Bacon Mcdsnte · Mar 22, 2018 at 10:47 PM 0
Share

You may need to also post your Player script Could you track and find all the places where you set the health?

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Legend_Bacon · Mar 23, 2018 at 12:29 AM

Hello there,

based on your player code, you seem to be reloading the scene whenever your player die. Doing that will restart the scene EXACTLY how it was the first time, player health included... Unless you have it saved externally.

A simple fix would be to save the player's health to PlayerPrefs. Then, on Start you can just set the currentHealth to the saved value. Note that you will have to manually manage this saved health.


I hope that helps!

Cheers,

~LegendBacon

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 Mcdsnte · Mar 23, 2018 at 12:58 AM 0
Share

Ah, ok I see what you mean! Ill re work some things and check again Thank you!

avatar image
0

Answer by Baktillus · Mar 22, 2018 at 04:33 PM

As a fan of simple solutions:
Make a deathplane. Some trigger below the edge of your screen. When the character falls out of screen, call a script that resets their position and damages them an appropriate amount.

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 Mcdsnte · Mar 22, 2018 at 10:23 PM 0
Share

@Baktillus Ive done all that, but the respawn restores health when it activates

avatar image Baktillus Mcdsnte · Mar 23, 2018 at 08:51 AM 0
Share

Oh I see! I meant not to use your respanw script (as it seems to reset all that) but ins$$anonymous$$d just reset the palyers position and deal damage to them.

Legend_Bacon already gave a great answer for using your respawn script :)

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

76 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How to refer to run a "void" in one c# script from another to respawn a player 0 Answers

Instantiating a prefab and values 1 Answer

How to change fall delay of a gameobject by time? 2 Answers


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