Hello! I’m making a car game. Right now I’m trying to add a car selection system. So far I have 3 scripts. CarSelect.cs, DataHandler.cs and DataImplementer.js. CarSelect and DataHandler are used as one car selector in the menu/garage, for example - I have 3 cars so far. I put all car prefabs in one place, so when I click to select car A, car B and C disappear, and when I select car B, car A and C disappear. And then DataImplementer does that in the actual “gameplay” scene. So if I have car B selected in the menu scene, it will appear in the gameplay scene instead of car B and C. By the way, all 3 cars are placed just like in menu scene, in the same position.
So the problem is, DataImplementer finds the GameObject “DataHandler” which contains the “DataHandler” script (they are named the same), and so car A has ID of 1, car B - 2 and car C - 3. So after finding it must find the selected car variable int (1,2 or 3). So if its car A, the variable is set to 1, so it will affect the gameplay scene. Everything is simple in the scripts and it should work with no problems, but unity won’t find the GameObject called “DataHandler” for some really weird reason. Each script has its own gameobject in the same menu scene, and car variables and buttons are already set.
Here is the DataImplementer.js script:
#pragma strict
var carSelected : int;
var Kapri : GameObject;
var BMM : GameObject;
var BMMD : GameObject;
function Start () {
carSelected = GameObject.Find("DataHandler").GetComponent(DataHandler).carSel;
if (carSelected == 1) {
Kapri.SetActive (true);
BMM.SetActive (false);
BMMD.SetActive (false);
}
else if (carSelected == 2) {
Kapri.SetActive (false);
BMM.SetActive (true);
BMMD.SetActive (false);
}
else if (carSelected == 3) {
Kapri.SetActive (false);
BMM.SetActive (false);
BMMD.SetActive (true);
}
}
function Update () {
}
Error at line GameObject.Find("DataHandler").GetComponent(DataHandler).carSel;
Unity error says: Assets/Standard Assets/DataImplementer.js(12,63): BCE0005: Unknown identifier: 'DataHandler'.
I don’t think it’s needed to post other scripts since they function like they should and cause no errors.
So people, please tell me whats wrong here? I have no idea at all. And I’m not a pro coder, just a beginner (noob). If more info is required then please tell me which exactly (scripts,screenshots etc). Thanks!
(Kapri, BMM, BMMD - are the 3 cars I was talking about)