- Home /
Question by
indiefreaks · Apr 19, 2012 at 03:19 PM ·
gameobjecttype
How do I know what type of GameObject my script is attached to?
I'm currently working on a simple script in C# that I want to execute differently depending either it is attached to a Camera or any other GameObject in my scene.
I thought making a type test on the GameObject would work like so:
void Update() { if(this.gameObject.GetType() == typeof(Camera)) DoSomethingToCamera(); else DoSomethingElse(); }
But it actually doesn't.
How can I achieve this please? Thanks
Comment
Your answer
Follow this Question
Related Questions
Assign a 'Transform' target to prefab by finding a 'GameObject' 1 Answer
Unity Crashes when C# script with code inside class but outside function is added to a GameObject 1 Answer
Acessing scripts in other game objects with prefabs, without using GameObject.Find 1 Answer
Randomizate bullets help 2 Answers