- Home /
Question by
markoin · Jun 26, 2020 at 09:20 AM ·
raycastgetcomponentintbool
How do I change a clicked on GameObjects variable when a boolean (Next Turn) is true?
So heres the idea: I tell the Farm to what City it should give its breadProductionPerTurn variable to (meaning what cities bread suply should it add to). Now heres my problem. After Next Turn has been clicked I want the bPPT of a Farm to be added to the clicked on GameObjects bread supply!
Bellow Is the update of my script where the selecting process happens. Do I need to make some kind of copy variable?
void Update() {
if (chosenow == true)
{
bool chosingButton = Input.GetKeyDown(KeyCode.M);
if (chosingButton == true)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, 1000))
{
if (hit.collider.gameObject.tag == "City")
{
displayNamefromFarm = hit.collider.gameObject.GetComponent<CityStats>().cityName;
//hit.collider.gameObject.GetComponent<CityStats>().bread;
//we need to tell the farm that when next turn is clicked it should add its bppt to the clicked on objects bread.
chosenow = false;
}
}
}
}
if (GameObject.Find("NextTurnChecker(Clone)").GetComponent<ItsTheNextTurn>().nextTurnHasBeenClicked == true)
{
}
}
Comment
Answer by markoin · Jun 25, 2020 at 07:16 PM
I solved the problem with finding the object that has its gameobject.name the same as the displayNameFromFarm