I created a script with a dynamic variable. This script is assigned to the GameManager of scene one. I want to take the object given to this dynamic variable, save it in another variable of a different script, and attach it to another object of scene 2.
If you will have many, you may need a more-flexible service locator approach.
The built-in FindObjectsOfType() form an excellent basis for any sort of service locator.
Here’s some other ideas:
ULTRA-simple static solution to a GameManager:
OR for a more-complex “lives as a MonoBehaviour” solution…
Simple Singleton (UnitySingleton):
Some super-simple Singleton examples to take and modify:
Simple Unity3D Singleton (no predefined data):
Unity3D Singleton with a Prefab (or a ScriptableObject) used for predefined data:
These are pure-code solutions, do not put anything into any scene, just access it via .Instance!
If it is a GameManager, when the game is over, make a function in that singleton that Destroys itself so the next time you access it you get a fresh one, something like:
public void DestroyThyself()
{
Destroy(gameObject);
Instance = null; // because destroy doesn't happen until end of frame
}
There are also lots of Youtube tutorials on the concepts involved in making a suitable GameManager, which obviously depends a lot on what your game might need.
And if you really insist on barebones C# singleton, here’s a Highlander: