- Home /
Enter Exit Vehicle doesnt work,Exit Vehicle is not working
Hey, the script is on my character. The ship has a collider on trigger. Entering the ship works fine. But exiting it doesnt work. I cant find the error ^^ Thanks for help guys.
bool inShip = false;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F) && inShip == true)
{
gameObject.SetActive(true);
inShip = false;
transform.parent = null;
}
}
private void OnTriggerStay2D(Collider2D collision)
{
if (Input.GetKeyDown(KeyCode.E) && collision.tag == "Ship" && inShip == false)
{
gameObject.SetActive(false);
inShip = true;
gameObject.transform.parent = collision.gameObject.transform;
}
}
Comment
Best Answer
Answer by xxmariofer · Feb 26, 2019 at 11:28 AM
hello, if you say gameObject.SetActive(false); it means that the gameobject with that script will be disable so the Update event will never be called again, so after you disable the gameObject you will not be able to execute the update code again. you can set the MeshRenderer enable to false if you want to just remove the mesh and will work
GetComponent<MeshRenderer>().enabled = false; //or true when you want to enable it
if yuuo must disable the gameobject you need to do it from a script thats not in the gameobject you want to disable.
Thank you very much! I had never thought in this direction.