- Home /
inherits error of camera while calling in script.
I am instantiating obtecs tin for loop. Using AddComponenti am attaching a script
I declared
private Camera camera;
In start function i given
camera = GameObject.Find("Main Camera").GetComponent<Camera>();
I am getting a warning
Assets/Scripts/buttonScript.cs(63,24): warning CS0108: buttonScript.camera' hides inherited member
UnityEngine.Component.camera'. Use the new keyword if hiding was intended
I don't have Unity in front of me so I cannot test it. Try:
camera = new GameObject.Find("$$anonymous$$ain Camera").GetComponent();
That probably doesn't work, but I'm just spit-balling. Or try:
camera = GameObject.Find("$$anonymous$$ain Camera").GetComponent<Camera>();
And see if that does anything for you.
Can we see the rest of your script? Your code seems fine and I would like to see what else it is doing.
@amphoterik: Your first suggestion makes no sense. It would try to create an instance of a class called "Find" that would be located as nested class in GameObject... That doesn't exist and that's the exact error he's getting when using your first "suggestion".
The searching for the Camera is totally fine. The compiler just warns about the variable.
Answer by Bunny83 · Jul 16, 2013 at 11:58 AM
First of all it's not an error, it's a warning.
Since your script is derived from MonoBehaviour your class already has a member called "camera". This member (inherited from Component) returns the Camera component that is attached to the same GameObject as your script. If there is no Camera it returns null.
You named your variable also "camera". That will hide the member that is already there. If you don't need the camera property of Component you can use the new keyword when declaring the variable:
private new Camera camera;
However it's better to just use a different name:
private Camera mainCam;
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Multiple Layout Errors with unitys GUI Layout 1 Answer
Boat script problems when changing platform to android 0 Answers
Login error with prime31 0 Answers
Why am I getting a parsing error? 1 Answer