- Home /
How to activate parent camera of gameobject
I have a parent camera I'm trying to enable through an empty gameobject with a collider and enabling script (attempt). I want to be able to throw this script on any number of gameobjects and have them enable the parented camera as my player enters the collision zone. I have searched around but I haven't found the solution and I am still learning C# so I can't tell what my problem is below... Please help!
void OnCollisionEnter(Collision col)
{
if(col.gameObject.name == "Player")
{
GameObject.Find("Camera").GetComponent(Camera).enabled = true;
//gameObject.GetComponentInParent<Camera>.enabled = true;
//Camera cam1 = this.gameObject.GetComponentInParent (Camera);
}
}
All of these bring up errors.
Answer by Cherno · Mar 12, 2015 at 03:13 PM
All of these bring up errors.
Nice. And would you be so kind and include what these errors actually say?
Also, try
GameObject.Find("Camera").GetComponent<Camera>().enabled = true;
SetActive activates or deactives the complete object, while .enabled can deactivate a part of a gameobject and the gameobject itself is still active.
I can't believe () was all I missed haha, thank you. I ended up using:
Camera ParentCamera = GetComponentInParent(); ParentCamera.enabled = true;
Your answer
Follow this Question
Related Questions
Having trouble understanding parenting with componants 0 Answers
Camera Collision Not Working 0 Answers
Camera collision 2 Answers
Camera bounce/collision 1 Answer