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 MMDCLXVI · Mar 07, 2013 at 10:28 PM · playerrespawn

Help - Player Respawn Help

To all the people of the Unity world wide website, if you could give me a moment of your time and help me figure out why my script isn't working. You see I've downloaded a simple health system that I obtain on the Unity Asset store (Grid Digital - Simple Health System) to create a health system, and have being trying to create a scrip that will respawn the player once they lost all there health.

However no matter what I try it doesn't work, you see I've coded a respawn script, and it works perfectly fine. var startPosition : Transform;

 function OnTriggerEnter(theCollider : Collider) 
 {
     theCollider.transform.position = startPosition.position;
 }

As you can see the script works, however when I tried to create my own script that states that the player will respawn once he/she loses all his health. var OneHeart : Texture2D; //These variables contain the textures used for the gui. var TwoHearts : Texture2D; var ThreeHearts : Texture2D; var FourHearts : Texture2D; var NoHearts : Texture2D;

 static var Hearts : int = 4; //This is the amount of hearts the character has.
 
 var startPosition : Transform;
 
 function OnTriggerEnter(theCollider : Collider)
 {
     if(Hearts < 0)
     {
     Hearts = 0;
     }
         else
         {
             theCollider.transform.position = startPosition.position;
             guiTexture.texture = FourHearts;
         }
     
 }    


For my life I can't see what is wrong, the script should work fine, but it doesn't. Additionally the health script form the Simple Health System is as followed...

 var OneHeart : Texture2D; //These variables contain the textures used for the gui.
 var TwoHearts : Texture2D;
 var ThreeHearts : Texture2D;
 var FourHearts : Texture2D;
 var NoHearts : Texture2D;
 
 static var Hearts : int = 4; //This is the amount of hearts the character has.
 
 function Update (){
     if(Hearts == 4){ //These if statements change the Gui Texture based on the static var Hearts.
         guiTexture.texture=FourHearts;
     }
     if(Hearts == 3){
         guiTexture.texture=ThreeHearts;
     }
     if(Hearts == 2){
         guiTexture.texture=TwoHearts;
     }
     if(Hearts == 1){
         guiTexture.texture=OneHeart;
     }
     if(Hearts == 0){
         guiTexture.texture=NoHearts;
     }
     
     
     if(Hearts > 4){ //These two if statements keep the static var Hearts within the 0-4 range.
         Hearts = 4;
     }
     if(Hearts < 0){
         Hearts = 0;
     }
 }

I was wondering if anyone could just look over my script and see why it is not working, any help would be great. Go dtí an chéad uair eile, slán leat

Comment
Add comment · Show 2
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 robertbu · Mar 08, 2013 at 02:30 AM 0
Share

I'm confused. For your respawn, what is setting off OnTriggerEnter(). You'r respawn will not work unless something is triggering this method.

As a double check, when you bring your player back to life, are you restting his health as well? If not, he may come back to to live to only immediately die again.

avatar image MMDCLXVI · Mar 08, 2013 at 07:31 PM 0
Share

I didn't know that, I though that if the player enter the trigger then the respawn script would work. But for some reason it doesn't, however do you now of anyway to have the player respawn when he/she loses all there health.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rednax20 · Mar 08, 2013 at 02:27 AM

I don't know what your doing exactly, but for player respawns you could always reload the level that you are on. Although I don't know what's wrong with your code

 if(Hearts = 0){
     Application.LoadLevel( "The level you are playing" );
 }

This won't work if you just want them to respawn, and you want the things that they have interacted with to remain.

I don't know much about transforms, but on a wild guess, is line 13 supposed to say

theCollider.transform.position = startPosition.transform. position;

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 MMDCLXVI · Mar 08, 2013 at 07:29 PM 0
Share

Your right, I didn't notice the mistake on line 13, thanks for pointing it out. I'll give it a check and see if changing that works. Additionally thanks for the help, I'll give the script you wrote a try, if I can't respawn the player, reloading the level will have to do.

avatar image
0

Answer by TargonStudios · Mar 08, 2013 at 03:45 AM

You could try Instantiating a new Character Controller with all the scripts attached and deleting the old one when the health equals 0.

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 MMDCLXVI · Mar 08, 2013 at 07:29 PM 0
Share

I'll give it a try, thanks for the help.

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

12 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

Related Questions

Falling off respawn script 1 Answer

Finding the player that walked into a ray? 1 Answer

How to run a script to only 1 player in a multiplayer fps 1 Answer

Player Respawn Script - Not Working 1 Answer

Damage script is screwed up...? what to do? 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