🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Integer value from child to parent

Started by
0 comments, last by narek5 10 months, 2 weeks ago

Hello there ?

Here I have 2 scripts

The Parent

public class car_onoff : MonoBehaviour

{

public GameObject BRman;

public int aval;


void Update()

{


if(Input.GetKeyDown("z"))

{

GetComponent<car_move1>().enabled = false;

BRman.SetActive(true);

BRman.GetComponent<charMove>().enabled = true;


}


else if(Input.GetKeyDown("x") && aval == 2)

{

GetComponent<car_move1>().enabled = true;

BRman.SetActive(false);

BRman.GetComponent<charMove>().enabled = false;

}

}

}

For your information - when I press Z key the person should leave the car and control from car passes to person. When I press X , the person should get into the car IF it is on trigger area.

Child code

public class checkTr : MonoBehaviour

{

public int aval;


void OnTriggerEnter2D(Collider2D other)

{

if (other.gameObject.CompareTag("PersPlayer"))

{

aval = 2;

}

}


void OnTriggerExit2D(Collider2D other)

{

if (other.gameObject.CompareTag("PersPlayer"))

{

aval = 3;

}

}

}


Triggers work well, but don't pass the integer value of aval to Parent.
I made this Parent/Child connection in order to move game objects and triggers together.


The question is, how to pass the integer value from child to parent ?

Thank you

This topic is closed to new replies.

Advertisement