- Home /
Move Objects in beginning of scene
Hey, I just wonder if someone know how to move an object in the beginning of a scene that I don't even notice it.
Been trying to implent a score script to my game and I managed to do that and make it survive from one scene to another when I die but the problem is now I can't get it to move to another spot on the next scene - Anyone got any ideas, please share then.
Ps, it's an GUI text I'm trying to move...
Answer by Arshia001 · Sep 10, 2011 at 09:11 AM
I don't know why you'd wanna move a GUI element around like that, but still...
When you load a scene, all the objects in it are loaded, including those which were not destroyed during a new level load. You can use this script in order to make the object singular (as in keep only one universal non-destroyable copy):
using UnityEngine;
using System.Collections;
public class SingularObject : MonoBehaviour
{
void Awake()
{
string prevName = name;
name = "";
GameObject other;
if (other = GameObject.Find(prevName))
{
other.SendMessage("OnSceneReloaded", SendMessageOptions.DontRequireReceiver);
DestroyImmediate(gameObject);
return;
}
name = prevName;
DontDestroyOnLoad(gameObject);
}
}
Just attach the script to any object and be sure to give the object a unique name across ALL your levels. Then, you'll know the scene's been reloaded when the OnSceneReloaded method of your script is called. That's where you can do the moving around, if you like.
Why is it saying:
The scripts file name does not match the name of the class defined in the script
It's a C# script. You have to rename the script file to EXACTLY the same name as the class it defines.
How did you say I would move it around in the second scene but not disturb it in the first scene?
O$$anonymous$$, now I'm gonna need some more info. What's the "first" and "second" scene?
Your answer
![](https://koobas.hobune.stream/wayback/20220612205817im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best practices about shared objects 0 Answers
Amnesia-like object moving? 1 Answer
all objects are abruptly disappeared 2 Answers
Keeping a score from one scene to another? 2 Answers
Finding objects on scene 1 Answer