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 · Jan 22, 2013 at 12:15 AM · spawnif statementhealth

Respawn Script activating once the player is dead

Hello to all, I was wondering if anyone out there on the this wide world of 8 billion people could lend me just a moment of there time and help me out with some scripting problems I've being having.

Know you see I've created a simple respawn script where the player will enter a trigger which simple then transports the players from his/hers current position and places then back to there original spawn point. The script is as following.....

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

Now the problem I'm having is that I'm using a simple health system that I obtain on the Unity Asset store (Grid Digital - Simple Health System), if you having seen it before the script that pretty much handlys the players health is a 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;
     }
 }


Now I am aware that it actually just changes the GUI health texture, but that is simple all I need it to do. My problem is though that I went to be able create an if statement that pretty much says that if the player losses all his health (texture health) then the respawn script kicks in sending the player back to his original position and then resets the health script so it looks like the player has all his/her health back.

Before anyone says, just figure it out for yourself, I am not looking for anyone to just write the script for me (though if anyone wants to that would be great) I wondering how you go around doing this so that I can learn more about scripting.

If anyone can help, tutorials, links, etc. that would be extremely helpfully.

Go dtí an chéad uair eile, slán leat

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 sparkzbarca · Jan 22, 2013 at 12:18 AM

 if(Hearts =< 0)
 {
 player.transform.position = startPosition;
 guiTexture.texture = FourHearts;
 }
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

10 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

Related Questions

,Can i use InvokeRepeating to spawn just 1 GameObject at a time? 1 Answer

Problem Spawning Enemys with Health. 2 Answers

Instantiate on value change 2 Answers

Instantiate on value change 4 Answers

Player Respawn After Death 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