added colors
This commit is contained in:
8
Assets/Scripts/Car Customization.meta
Normal file
8
Assets/Scripts/Car Customization.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95551c0cc76300044b242a09b1bbc0ef
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
33
Assets/Scripts/Car Customization/Change Car Color.cs
Normal file
33
Assets/Scripts/Car Customization/Change Car Color.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ChangeCarColor : MonoBehaviour
|
||||
{
|
||||
public GameObject[] materialParts;
|
||||
public Material[] defaultColors;
|
||||
// Start is called before the first frame update
|
||||
|
||||
private void OnEnable() {
|
||||
|
||||
for (int i = 0; i < materialParts.Count(); i++)
|
||||
{
|
||||
GameObject part = materialParts[i];
|
||||
Material color = defaultColors[i];
|
||||
MeshRenderer renderer = part.GetComponent<MeshRenderer>();
|
||||
|
||||
renderer.material = color;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void ChangeColor(Material color)
|
||||
{
|
||||
foreach (GameObject part in materialParts)
|
||||
{
|
||||
MeshRenderer renderer = part.GetComponent<MeshRenderer>();
|
||||
renderer.material = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Car Customization/Change Car Color.cs.meta
Normal file
11
Assets/Scripts/Car Customization/Change Car Color.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ee5992a8d68a894cba0612b0c18c3db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
149
Assets/Scripts/Car Customization/Garage.cs
Normal file
149
Assets/Scripts/Car Customization/Garage.cs
Normal file
@@ -0,0 +1,149 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Garage : MonoBehaviour
|
||||
{
|
||||
GameObject CurrentCar;
|
||||
public Button HotrodButton;
|
||||
public GameObject HotrodGarage;
|
||||
public GameObject Hotrod;
|
||||
public Button RacecarButton;
|
||||
public GameObject RacecarGarage;
|
||||
public GameObject Racecar;
|
||||
public Button FordButton;
|
||||
public GameObject FordGarage;
|
||||
public GameObject Ford;
|
||||
public Button[] ColorButtons;
|
||||
public Material[] Colors;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
HotrodButton.onClick.AddListener(SelectHotrod);
|
||||
RacecarButton.onClick.AddListener(SelectRacecar);
|
||||
FordButton.onClick.AddListener(SelectFord);
|
||||
|
||||
ColorButtons[0].onClick.AddListener(SelectBlack);
|
||||
ColorButtons[1].onClick.AddListener(SelectBlue);
|
||||
ColorButtons[2].onClick.AddListener(SelectBrown);
|
||||
ColorButtons[3].onClick.AddListener(SelectGray);
|
||||
ColorButtons[4].onClick.AddListener(SelectGreen);
|
||||
ColorButtons[5].onClick.AddListener(SelectOrange);
|
||||
ColorButtons[6].onClick.AddListener(SelectPink);
|
||||
ColorButtons[7].onClick.AddListener(SelectRed);
|
||||
ColorButtons[8].onClick.AddListener(SelectTurquoise);
|
||||
ColorButtons[9].onClick.AddListener(SelectViolet);
|
||||
ColorButtons[10].onClick.AddListener(SelectWhite);
|
||||
ColorButtons[11].onClick.AddListener(SelectYellow);
|
||||
|
||||
|
||||
disable();
|
||||
SelectHotrod();
|
||||
}
|
||||
|
||||
void enable(GameObject carGarage)
|
||||
{
|
||||
carGarage.SetActive(true);
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
HotrodGarage.SetActive(false);
|
||||
RacecarGarage.SetActive(false);
|
||||
FordGarage.SetActive(false);
|
||||
}
|
||||
|
||||
void SelectHotrod()
|
||||
{
|
||||
disable();
|
||||
enable(HotrodGarage);
|
||||
CurrentCar = Hotrod;
|
||||
}
|
||||
|
||||
void SelectRacecar()
|
||||
{
|
||||
disable();
|
||||
enable(RacecarGarage);
|
||||
CurrentCar = Racecar;
|
||||
}
|
||||
|
||||
void SelectFord()
|
||||
{
|
||||
disable();
|
||||
enable(FordGarage);
|
||||
CurrentCar = Ford;
|
||||
}
|
||||
|
||||
void SelectBlack()
|
||||
{
|
||||
Material color = Colors[0];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectBlue()
|
||||
{
|
||||
Material color = Colors[1];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectBrown()
|
||||
{
|
||||
Material color = Colors[2];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectGray()
|
||||
{
|
||||
Material color = Colors[3];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectGreen()
|
||||
{
|
||||
Material color = Colors[4];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectOrange()
|
||||
{
|
||||
Material color = Colors[5];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectPink()
|
||||
{
|
||||
Material color = Colors[6];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectRed()
|
||||
{
|
||||
Material color = Colors[7];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectTurquoise()
|
||||
{
|
||||
Material color = Colors[8];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectViolet()
|
||||
{
|
||||
Material color = Colors[9];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectWhite()
|
||||
{
|
||||
Material color = Colors[10];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
|
||||
void SelectYellow()
|
||||
{
|
||||
Material color = Colors[11];
|
||||
CurrentCar.GetComponent<ChangeCarColor>().ChangeColor(color);
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Garage : MonoBehaviour
|
||||
{
|
||||
public Button HotrodButton;
|
||||
public GameObject HotrodGarage;
|
||||
public Button RacecarButton;
|
||||
public GameObject RacecarGarage;
|
||||
public Button FordButton;
|
||||
public GameObject FordGarage;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
HotrodButton.onClick.AddListener(SelectHotrod);
|
||||
RacecarButton.onClick.AddListener(SelectRacecar);
|
||||
FordButton.onClick.AddListener(SelectFord);
|
||||
|
||||
disable();
|
||||
HotrodGarage.SetActive(true);
|
||||
}
|
||||
|
||||
void enable()
|
||||
{
|
||||
HotrodGarage.SetActive(true);
|
||||
RacecarGarage.SetActive(true);
|
||||
FordGarage.SetActive(true);
|
||||
}
|
||||
|
||||
void disable()
|
||||
{
|
||||
HotrodGarage.SetActive(false);
|
||||
RacecarGarage.SetActive(false);
|
||||
FordGarage.SetActive(false);
|
||||
}
|
||||
|
||||
void SelectHotrod()
|
||||
{
|
||||
disable();
|
||||
HotrodGarage.SetActive(true);
|
||||
}
|
||||
|
||||
void SelectRacecar()
|
||||
{
|
||||
disable();
|
||||
RacecarGarage.SetActive(true);
|
||||
}
|
||||
|
||||
void SelectFord()
|
||||
{
|
||||
disable();
|
||||
FordGarage.SetActive(true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user