- Home /
attaching camera after an event occurs
Hi everybody! I have a simple question:
I would like to attach the Main Camera object to my player AFTER it has collided with the ground (the player starts in the air..he then falls down and reach the floor). From that moment i want to attach the object Main Camera to him using the script (maybe in C#).
So the structure of the script will be the following: (--the script is attached to the player!--)
I define the object "Main Camera" (...wich i suppose it's a Transform); When Player collides with the ground { attach the Game Object "Main Camera" to him; }
now..how to write that thing in C#?? the collision part is clear to me (`if (collision.gameObject.name == "Floor")`
the problem is defining the Main Camera and attaching it to Player!
Thank you all in any case! Fabrizio
Answer by m.alekseev · Aug 27, 2012 at 05:28 PM
Add this at collision:
Camera newMainCamera = gameObject.AddComponent<Camera>();
gameObject.tag = "MainCamera";
thank you very very much! i know it's a simple thing but i'm getting started right now with unity and the simple fact i'm studiyng c# doesn't help all the times!
again, thank you!
Your answer
Follow this Question
Related Questions
Attaching an object to a bone? 3 Answers
problem at adding script 1 Answer
Attach an object to another that is an animation 2 Answers
Applying a texture to a sphere 1 Answer
Visual Studio won't attach to Unity, even after Vs Tools for Unity update 9 Answers