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 /
This question was closed Apr 21, 2013 at 02:01 PM by fafase for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by WesterlyCarrot9 · Apr 20, 2013 at 02:36 PM · javascriptguitriggerloadlevelhealth

LoadLevel Health Question.

OK so i use those two script you can see below for my player's hearts. How is it possible to make the hearts be minus 1 when i press the Respawn button and the level is loaded? Also, i noticed that some objects that were destroyed at first, were loaded together with the level and i dont really want that. Thanks!

 FallDamage.js
 
 var hearts : int = 3;
 
 function OnGUI(){
     GUI.Box(new Rect(20,20,100,40), "Hearts : " + hearts);
     
     if(hearts < 0){
         hearts = 0;
     }        
 }


 TriggerFloor.js
 
 var showGUI : boolean = false;
 
 function OnTriggerEnter(other:Collider){
     var otherScript : FallDamage = GameObject.Find("Player").GetComponent(FallDamage);
     otherScript.hearts -= 1;
     
     if(other.gameObject.name == "Player"){
         showGUI = true;
     }    
 }
 
 function OnGUI(){
     if(showGUI){
         if(GUI.Button(new Rect(20,70,100,50), "Respawn")){
             Application.LoadLevel(Application.loadedLevel);
         }    
     }
 }

     

     
Comment
Add comment · Show 1
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 WesterlyCarrot9 · Apr 20, 2013 at 05:11 PM 0
Share

um anyone?

1 Reply

  • Sort: 
avatar image
3
Best Answer

Answer by fafase · Apr 20, 2013 at 05:16 PM

Maybe you want to avoid to reload the whole level since it seems you only want to respawn your player.

So you would have:

 function OnGUI(){
   if(showGUI){
     if(GUI.Button(new Rect(20,70,100,50), "Respawn")){
        transform.position = originalPosition;
        hearts = -1;
     }
    }
 }

Now if you really want to reload you could have a Start

 function Start(){
    hearts = -1;
 }

then you can use DontDestroyOnLoad to save some object from destruction:

http://docs.unity3d.com/Documentation/ScriptReference/Object.DontDestroyOnLoad.html

Comment
Add comment · Show 13 · 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 WesterlyCarrot9 · Apr 20, 2013 at 05:46 PM 0
Share

Unfortunately i get the error $$anonymous$$ identifier "originalPosition". :(

avatar image WesterlyCarrot9 · Apr 20, 2013 at 05:48 PM 0
Share

What's more, is this going to work is there is no Application.LoadLevel? :S

avatar image WesterlyCarrot9 · Apr 20, 2013 at 05:57 PM 0
Share

Ok i added this at the start of the script: var original = Transform; . But when i press the button nothing happens :/

avatar image fafase · Apr 20, 2013 at 06:03 PM 0
Share

Because you need to assign something to that variable.

 function Start(){
    original.position = transform.position;
 } 
avatar image WesterlyCarrot9 · Apr 20, 2013 at 06:19 PM 0
Share

Ok it seems that the moment i write the above lines: function Start(){ etc. i get a "Cannot convert 'UnityEngive.Vector3' to 'UnityEngine.Transform' error.

Show more comments

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

Basketball Score counter 1 Answer

How do I use a trigger to change the GUIText 2 Answers

Health bar only updates on character death 1 Answer

4.6 Trigger.js Wrong command is running. Help? 0 Answers

Can't move GUI 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