- Home /
Objects stop rotating when I go a scene, and then back to the original
Okay! This is kind of long but I will try to be concise:
Scene 0 has this script on a cube to make it randomly rotate:
function Start ()
{
var v3 = Vector3(Random.Range(-50.0, 50.0), Random.Range(-50.0, 50.0), Random.Range(-50, 50));
GetComponent.<Rigidbody>().AddTorque(v3 * 2);
}
Then in Scene 1 this script brings me back to Scene 0:
#pragma strict
function LoadScene ()
{
Application.LoadLevel("scene0");
}
So if the LoadLevel Script is in Scene 1, it brings me back to Scene 0 and the cube is at its default position, NOT rotating.
However, if I put the the LoadScene in Scene 0, run it, it will keep rotating with a new random rotation.
I have tried switching the rotation to a Function Update, FixedUpdate none worked.
Answer by Rhylvin2015 · Jul 27, 2015 at 10:22 AM
That's because you're just going to another scene and nothing was save. basically what I'm saying is you did something on scene 0, didn't save anything went to scene 1 who wants to go back to scene 0 and since nothing was saved it wounded up to a default. Try using PlayerPrefs. http://docs.unity3d.com/ScriptReference/PlayerPrefs.html
Its a very awesome feature of Unity Scripts that lets you save an Int, Float and a String
I don't know if this will work but the idea is there, in your Scene0 save your v3 with this
PlayerPrefs.SetFloat("v3",v3);
//I don't know either if the v3 returns a String or a Float or an Int. just change if its not Float.
this should be the correct term to get that random rotation
GetComponent.<Rigidbody>().AddTorque(PlayerPrefs.GetFloat("v3") * 2);
Edit time!
So I tried this and nothing :(
But someone actually came up with the idea of time.timescale being set to 0 in order to pause... and that was it.
$$anonymous$$y menu scene wasnt going back to time.timescale = 1
So I changed it so that it does... and now it is working!
If you change you answer so that it incorporates time.timescale i'll hit the check mark!