- Home /
Spawn Object based on previous Scene Selection?
Hey Iam working on a Player or bettter: Car selection sCreen which looks like this at the moment: https://dl.dropboxusercontent.com/content_link/P8vHCsIGh1SOvJtvA9hEN9cOZcFVS1rA7aXRb61gjP3Y4ezqQZK3VnhTh8RKwZSB/file
the code for this is the following:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SlotSelect : MonoBehaviour {
public RectTransform navigator1;
int nav1Pos = 0;
public Transform[] cars = new Transform[12];
public Transform displayAt; // the position where the car is supposed to be displayed
public Transform selectedCar;// the car which is currently being displayed
public RectTransform[] slots = new RectTransform[12];
public int jumpAmount = 4;
public Text textShowNav1;
void Start(){
MoveNav1(0);
}
void Update () {
// move up
if(Input.GetKeyDown(KeyCode.UpArrow)){
MoveNav1(-jumpAmount);
}
if(Input.GetKeyDown(KeyCode.LeftArrow)){
MoveNav1(-1);
}
if(Input.GetKeyDown(KeyCode.DownArrow)){
MoveNav1(jumpAmount);
}
if(Input.GetKeyDown(KeyCode.RightArrow)){
MoveNav1(1);
}
if(Input.GetKeyDown(KeyCode.Return)){
selectNav1(nav1Pos);
}
}
void MoveNav1(int change){
if(change > 0){
if(nav1Pos+change < slots.Length-1){
nav1Pos += change;
}else{
nav1Pos = slots.Length-1;
}
}else{
if(nav1Pos+change >= 0){
nav1Pos += change;
}else{
nav1Pos = 0;
}
}
navigator1.position = slots[nav1Pos].position;
textShowNav1.text = "Nav 1 is at slot "+ nav1Pos;
}
void selectNav1(int nav1Pos){
selectedCar.gameObject.SetActive(false); //deactivate the previously selected car
selectedCar = cars[nav1Pos]; // assign the selected car
selectedCar.position = displayAt.position; //move it to correct position
selectedCar.gameObject.SetActive(true); // set the car active
}
}
so, my problem is now, how do i get the previous selected car (which is stored in the "public Transform selectedCar;" i think into another Scene? so imagine a Start Game Button with
Application.LoadLevel("Game");
at the bottom which brings you to the next scene with your selected car
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612043906im_/https://answers.unity.com/themes/thub/images/avi.jpg)