- Home /
Object no longer moves, when the level is reloaded.
Basically, this is attached to a "movingTarget", target moves back and forward. When it gets clicked a guitext appears. I'm not assigning the text because the texts are randomly generated from prefabs. No issues when loading the scene for the first time, everything works as intended. However once the pause menu script's Temp is called (has a return to menu button, loads a different scene, which then has a button to replay this one) and you try replaying the scene, movingTarget no longer moves. Any ideas?
public class MovingTarget : MonoBehaviour {
public GameObject movingTarget;
public float directionSpeed;
public float distance;
private GUIText answer1;
private GUIText answer2;
private GUIText answer3;
private bool gameOvr = false;
//Private variables
private float originalPosition; //Original platform position
private float useSpeed; //Sexier code...
void OnMouseDown ()
{
if (Input.GetMouseButtonDown(0))
{
directionSpeed = 0;
useSpeed = 0;
if(gameObject.name == "Mid Ground Target")
answer2.enabled = true;
if(gameObject.name == "Foreground Target")
answer1.enabled = true;
if(gameObject.name == "Background Target")
answer3.enabled = true;
}
}
void Start()
{
originalPosition = movingTarget.transform.position.x;
useSpeed = -directionSpeed;
answer1 = GameObject.Find ("Answer 1").GetComponent<GUIText> ();
answer2 = GameObject.Find ("Answer 2").GetComponent<GUIText> ();
answer3 = GameObject.Find ("Answer 3").GetComponent<GUIText> ();
}
// Update is called once per frame
void Update ()
{
//Flip direction when destination is reached
if (originalPosition - movingTarget.transform.position.x > distance)
useSpeed = directionSpeed;
else if (originalPosition - movingTarget.transform.position.x < -distance)
useSpeed = -directionSpeed;
//Translate the platform
movingTarget.transform.Translate (useSpeed * Time.deltaTime, 0, 0);
if (answer1.enabled && answer2.enabled && answer3.enabled)
{
if(!PauseMenuScript.pauseMenuEnabled)
{
Screen.showCursor = true;
PauseMenuScript.Temp ();
}
}
}
}
PS: This isn't my code, it's a group thing and this is an adaptation of the script I wrote for a balancing bar type of game, thus comments might be messy and the script may be awkward at times.
Answer by Professor Snake · Mar 21, 2014 at 03:49 PM
You're most likely pausing with Time.timeScale=0
, which carries over when you reload. Try adding Time.timeScale=1;
on your Awake function.
WEW, good catch... and after I had this in all other scenes. Ugh. Thanks a lot! Feel free to close this thread.
(Long answer short: since pause menu was doing different stuff in different scenes, I literally just forgot to unpause in this one)
Your answer
![](https://koobas.hobune.stream/wayback/20220613140826im_/https://answers.unity.com/themes/thub/images/avi.jpg)