if(type == 1)
{
CannotBuildHere = false;
GenerateTiles script = GetComponent<GenerateTiles>();
GUIScript scr = GetComponent<GUIScript>();
GameObject obj = GameObject.Find ("NumberOfPopultaion");
GameObject obj2 = GameObject.Find ("GameMoney");
GameObject obj3 = GameObject.Find ("SchoolNumber");
SchoolScript s1 = GetComponent<SchoolScript>();
ConstructSchoolScript sSchool = GetComponent<ConstructSchoolScript>();
if(scr.SchoolNumber >= 9)
{
return;
}
if(scr.NumberOfFood >= scr.NumberOfPopulation)
{
return;
}
if(!script.CheckOccupied(hit.collider.gameObject, 2, 2))
{
audio.PlayOneShot(audio3);
script.SetOccupied(hit.collider.gameObject ,2, 2);
scr.NumberOfPopulation -= 150;
scr.GameMoney -= 2000;
scr.SchoolNumber += 1;
GameObject myObj= (GameObject)Instantiate (school, hit.collider.gameObject.transform.position, Quaternion.identity);
Instantiate (SchoolHD, hit.collider.gameObject.transform.position, Quaternion.identity);
Instantiate (constructschool, hit.collider.gameObject.transform.position, Quaternion.identity);
type2 = 1;
Debug.Log("School built");
}
else
{
CannotBuildHere = true;
audio.PlayOneShot(rejectaudio);
print ("Cannot build here");
}
else if(type == 2)
{
CannotBuildHere = false;
GUIScript scr = GetComponent<GUIScript>();
GenerateTiles script = GetComponent<GenerateTiles>();
GameObject obj = GameObject.Find ("NumberOfPopultaion");
GameObject obj2 = GameObject.Find ("GameMoney");
GameObject obj4 = GameObject.Find ("HospitalNumber");
if(scr.HospitalNumber >= 2)
{
return;
}
if(scr.NumberOfFood >= scr.NumberOfPopulation)
{
return;
}
if(!script.CheckOccupied(hit.collider.gameObject, 2, 2))
{
audio.PlayOneShot(audio3);
script.SetOccupied(hit.collider.gameObject,2, 2);
Instantiate (hospitalHD, hit.collider.gameObject.transform.position, Quaternion.identity);
Instantiate (constructhospital, hit.collider.gameObject.transform.position, Quaternion.identity);
GameObject myObj = (GameObject)Instantiate (hospital, hit.collider.gameObject.transform.position, Quaternion.identity);
type2 = 2;
//Instantiate (HospitalText, hit.collider.gameObject.transform.position, Quaternion.identity);
Debug.Log("Hospitall built");
scr.NumberOfPopulation -= 100;
scr.GameMoney -= 3000;
scr.HospitalNumber += 1;
}
else
{
CannotBuildHere = true;
audio.PlayOneShot(rejectaudio);
print ("Cannot build here");
}
//sell buildings
else if(type == 16)
{
GenerateTiles script = GetComponent<GenerateTiles>();
GameObject obj2 = GameObject.Find ("GameMoney");
GUIScript scr = GetComponent<GUIScript>();
if(script.CheckOccupied(hit.collider.gameObject,1, 1))
{
for(int i = 0; i<script.board_size_x_; ++i)
{
for(int j = 0; j<script.board_size_z_; ++j)
{
if(script.tileObj[i,j] == hit.collider.gameObject)
{
if(script.tileObj[i,j]== school)
{
audio.PlayOneShot(sell);
Destroy (GameObject.FindWithTag ("buildings"));
Destroy (GameObject.FindWithTag ("HP"));
Destroy (GameObject.FindWithTag("text"));
}
else{
print ("There is no school");
}
}
}
}
}
You didn’t close your code tags properly. So what’s the error and at what line is it pointing at?
Lets said I have create 2 different buildings using instatinate, then for the type == 16, I want to sell the buildings, how do I code as such as where when I click on the mouse cursor from the tile maps, it know which buildings it has created. The line 33 fro, the sell building part is not working which is the one I am trying to solve it.
help