- Home /
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);
}
}
$$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.
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
Put some Debug.Log entries to try and see whats going on.
ok now its good but its moving only my main camera...
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?
FIXED.
var player : GameObject; // <-- here i put my first person controller
player.transform.position .....
thanks everyone
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.
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
Follow this Question
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