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 nevo · Oct 29, 2013 at 05:41 PM · javascripttransform.position

whats wrong with my save/load script? (transform.position)

whats wrong? when im save position and try load script changing my position wrong... SCRIPT: function OnGUI() {

 if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUIManager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(Rect(10,10,50,50),save))
         {
             PlayerPrefs.GetFloat.Vector3(newXpos, newYpos, newZpos, transform.position);
             PlayerPrefs.SetInt("currentHealth", manager.currentHealth);
             ;
         }    
     }    
     if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUIManager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(new Rect(35,35,100,50),load))
             { 
                 manager.currentHealth = PlayerPrefs.GetInt("currentHealth");
              var newXpos : float = PlayerPrefs.GetFloat("PlayerX");
              var newYpos : float = PlayerPrefs.GetFloat("PlayerY");
              var newZpos : float = PlayerPrefs.GetFloat("PlayerZ");
              transform.position = Vector3(newXpos, newYpos, newZpos);
                 
                 
             }
                  }
Comment
Add comment · Show 5
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 meat5000 ♦ · Oct 29, 2013 at 06:23 PM 0
Share

$$anonymous$$aybe something to do with having 4 values in a Vector3?

  PlayerPrefs.GetFloat.Vector3(newXpos, newYpos, newZpos, transform.position);

Doesn't this throw an error?

I'm not sure, but I don't think GetFloat works that way.

avatar image nevo · Oct 29, 2013 at 06:25 PM 0
Share

nope but im trying now this way :

 if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUI$$anonymous$$anager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(Rect(10,10,50,50),save))
         {    
             PlayerPrefs.SaveObject(GameObject.FindGameObjectWithTag("Player"));
             PlayerPrefs.Setfloat("xpos", transform.position.x);
             PlayerPrefs.Setfloat("ypos", transform.position.y);
             PlayerPrefs.Setfloat("zpos", transform.position.z);
 //            PlayerPrefs.GetFloat.Vector3(newXpos, newYpos, newZpos, transform.position);
             PlayerPrefs.SetInt("currentHealth", manager.currentHealth);
             ;
         }    
     }    
     if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUI$$anonymous$$anager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(new Rect(35,35,100,50),load))
             { 
                 manager.currentHealth = PlayerPrefs.GetInt("currentHealth");
 
                 transform.position.x = PlayerPrefs.GetFloat ("xpos");
                 transform.position.y = PlayerPrefs.GetFloat ("ypos");
                 transform.position.z = PlayerPrefs.GetFloat ("zpos");

 

and still dont work. this move me to wrong position

avatar image meat5000 ♦ · Oct 29, 2013 at 06:33 PM 0
Share

Put some Debug.Log entries to try and see whats going on.

avatar image nevo · Oct 29, 2013 at 06:54 PM 0
Share

ok now its good but its moving only my main camera... screen

and here code:

 if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUI$$anonymous$$anager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(Rect(10,10,50,50),save))
         {    
             PlayerPrefs.SetFloat("x",transform.position.x);
             PlayerPrefs.SetFloat("y",transform.position.y);
             PlayerPrefs.SetFloat("z",transform.position.z);
                 PlayerPrefs.SetInt("currentHealth", manager.currentHealth);
             ;
         }    
     }    
     if(paused) /// if escaped pressed display menu
     {        manager = GameObject.FindGameObjectWithTag("Player").GetComponent(GUI$$anonymous$$anager);
             GameObject.FindGameObjectWithTag("Player");
             if (GUI.Button(new Rect(35,35,100,50),load))
             { 
             
                 transform.position = new Vector3(PlayerPrefs.GetFloat("x"),PlayerPrefs.GetFloat("y"),PlayerPrefs.GetFloat("z"));
                     manager.currentHealth = PlayerPrefs.GetInt("currentHealth");
 



what i must do to move all elements?

avatar image nevo · Oct 29, 2013 at 07:08 PM 0
Share

FIXED.

 var player : GameObject; // <-- here i put my first person controller
 player.transform.position .....

thanks everyone

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Stormizin · Oct 29, 2013 at 07:08 PM

You need to make a Hierarchy group and put all the components inside this Group that's the way you'll move the objects simultaneously. Moving the group you will move the components.

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 nevo · Oct 29, 2013 at 07:32 PM 0
Share

one more question. can i make go to function inside of if(GUI.Button) ?? because dont work... code:

            if (GUI.Button(new Rect(35,35,100,50),load))
             { 
                loadchar();

``}

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

17 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

Related Questions

Setting Scroll View Width GUILayout 1 Answer

Transform position to a public variable 1 Answer

Script causing huge lag 0 Answers

How do I add a vector3.lerp or movetoward 1 Answer

Vector3.Lerp doesn't work 3 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