Advertisement

Integer value from child to parent

Started by August 03, 2023 01:14 PM
0 comments, last by narek5 1 year, 4 months 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