car selection, help!
Hi,
I made a simple car selection and everything works fine. choose a car and drive the same car that has been selected.
the problem is when I select second car for example and play and return to the first scene when I click next button its show the third car not second, that's cause me a problem because the first car does not get disappear, I think it's happened because the number of car that I selected saved somewhere and when click next button show me the number that follows.
Needs help please! sorry about my english.
1- menu, attached to cars parent:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class menu : MonoBehaviour
{
public static int x;
void Start()
{
x = gameObject.transform.childCount;
for(int i=1;i<x;i++) {
gameObject.transform.GetChild (i).gameObject.SetActive (false);
}
}
}
2-function, at the first scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class functions : MonoBehaviour
{
public GameObject player;
public static int i=0;
public static int selected;
public void Back()
{
if (i <= 0)
return;
player.transform.GetChild (i).gameObject.SetActive (false);
i--;
player.transform.GetChild (i).gameObject.SetActive (true);
}
public void Select()
{
SceneManager.LoadScene (3);
}
public void Next()
{
if (i >= menu.x-1)
return;
player.transform.GetChild (i).gameObject.SetActive (false);
i++;
player.transform.GetChild (i).gameObject.SetActive (true);
}
}
3-functiongame, at the second scene:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class functionsgame : MonoBehaviour
{
public GameObject players;
void Start() {
players = GameObject.FindGameObjectWithTag ("Player");
for(int i=0;i<players.transform.childCount;i++)
{
players.transform.GetChild (i).gameObject.SetActive (false);
}
players.transform.GetChild (functions.i).gameObject.SetActive (true);
}
}
Your answer
Follow this Question
Related Questions
Unity 5.2.0f3 Triggers Broken?? 1 Answer
car game unity 5 1 Answer
[SOLVED] Camera severly jittering 1 Answer
How to use NavMeshAgent on unity 5 car 0 Answers
How to make player move from one track to the other gradually? 1 Answer