Hi, I have a problem where i can’t seem to figure out how to save a Gameobject as it has been positioned at a certain spot which is used to select a spawnpoint where the selected object shall start.
Basically what i’m trying to do is to select 5 characters and put them in certain positions by clicking on them. Whatever position you choose for a character the character should spawn in a corresponding place in the next scene. but i don’t know how to transfer them over to the right place.
i should probably mention that i know the basics of Unity and is a complete beginner.
Variables that are declared with the static keyword will not lose the data on scene loads. So you can store the character positions in a static variable in one scene, and load from it in the next scene.
Attach the script to an empty GameObject in both scenes.
using UnityEngine;
public class CharacterSpawnPositions : MonoBehaviour {
public static Vector3[] positionArray = new Vector3[5];
}
Then you can access the positions directly from other scripts:
// store the character's position
CharacterSpawnPositions.positionArray[0] = transform.position;
// position the character
transform.position = CharacterSpawnPositions.positionArray[0];