-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCarSelection.cs
88 lines (67 loc) · 2.06 KB
/
CarSelection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class CarSelection : MonoBehaviour
{
[Header("Buttons and Canvas")]
public Button nextButton;
public Button previousButton;
[Header("Cameras")]
public GameObject cam1;
public GameObject cam2;
[Header("Buttons and Canvas")]
public GameObject SelectionCanvas;
public GameObject SkipButton;
public GameObject PlayButton;
public GameObject MapUI; // Reference to the MapUI object
private int currentCar;
private GameObject[] carList;
private void Awake()
{
SelectionCanvas.SetActive(false);
PlayButton.SetActive(false);
cam2.SetActive(false);
chooseCar(0);
}
private void Start()
{
currentCar = PlayerPrefs.GetInt("CarSelected");
carList = new GameObject[transform.childCount];
for(int i = 0; i < transform.childCount; i++)
carList[i] = transform.GetChild(i).gameObject;
foreach (GameObject go in carList)
go.SetActive(false);
if(carList[currentCar])
carList[currentCar].SetActive(true);
}
private void chooseCar(int index)
{
previousButton.interactable = (currentCar !=0);
nextButton.interactable = (currentCar != transform.childCount - 1);
for(int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(i == index);
}
}
public void switchCar(int switchCars)
{
currentCar += switchCars;
chooseCar(currentCar);
}
public void playGame()
{
PlayerPrefs.SetInt("CarSelected", currentCar);
MapUI.SetActive(true); // Show the MapUI instead of loading the scene
SelectionCanvas.SetActive(false);
}
public void skipButton()
{
SelectionCanvas.SetActive(true);
PlayButton.SetActive(true);
SkipButton.SetActive(false);
cam1.SetActive(false);
cam2.SetActive(true);
}
}