Question by
Jammius · Mar 04, 2021 at 10:10 PM ·
oncollisionentersetactivechild object
Deactivate gameobject childen in the Game Manager Script
I have a GameManager, that im trying to use to call the parent object and deactivate the child (the player) on collision enter, I've tried a number of options and it never deactivates the child. Some help please.
public class GameMaster : MonoBehaviour
{
public GameObject restartText;
public GameObject playerMaster;
public GameObject respawnPoint;
public Camera mainCam;
public Camera deathCam;
void Start()
{
restartText.SetActive(false);
deathCam.enabled = false;
playerMaster = GameObject.Find("Player");
}
void Update()
{
if (Input.GetKey(KeyCode.R))
{
Respawn();
playerMaster.SetActive(true);
mainCam.enabled = true;
deathCam.enabled = false;
}
}
public void GameOver()
{
restartText.SetActive(true);
}
public void Respawn()
{
playerMaster.transform.position = respawnPoint.transform.position;
restartText.SetActive(false);
}
private void OnCollisionEnter(Collision collision)
{
if (playerMaster)
{
if (collision.gameObject.tag == "enemy" || collision.gameObject.tag == "missile")
{
playerMaster.SetActive(false);
mainCam.enabled = false;
deathCam.enabled = true;
FindObjectOfType<GameMaster>().GameOver();
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613030202im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to hide and show ui buttons. 1 Answer
Activate all child objects in a Parent object 2 Answers
Whats wrong with this simple code? 1 Answer
WaitForSeconds doesn't work when seconds is greater than 2 0 Answers
OnCollisionEnter - Enabled C# 1 Answer