|
Current code in NodeControllerRevCsharp.cs:
Resultant error message:
C# newbie having a little trouble accessing my Main Camera in code - I've got this working in JS, so I assume the solution to this is just extraordinary ignorance. I've looked up the error on UnityAnswers ( http://answers.unity3d.com/search.html?redirect=search%2Fsearch&q=CS0176 ) and either the existing answers are unhelpful or I just don't understand 'em. Previous attempts to solve the issue can be found near the end of the code, commented out. All yielded a further rats nest of errors. Would anybody care to hazard a solution? And perhaps a bug-finding methodology so I'm not constantly bothering the good people of Unity Answers? =) Thanks for reading, --Rev
(comments are locked)
|
|
I've had a look at Rev's code and after some experimentation ... You need to get component by the name of the class so it needs to be in quotes "className" It's also possible to call GetComponent by type http://unity3d.com/support/documentation/ScriptReference/GameObject.GetComponent.html I'm quite new to c# but I know it's a stickler for type. So we ended up GetComponent-ing as className and also making sure that the variable was the same type. There was also a problem that CameraNode was defined in 2 different places, once in NodeController as a public class and once in CameraController as a sub-class ( member variable ?) We eliminated the class in NodeController and changed to so that we are using the definition of the class from CameraController And that works. Perfectly. Thanks! --Rev
Apr 06 '12 at 12:52 PM
Reverend Speed
(comments are locked)
|
|
Either use Camera.main or GameObject.Find("Main Camera"). GameObject.Find will find an active game object with the specified name. gameObject and GameObject are two different things. gameObject refers to the game object the script is attached to and GameObject refers to the class and class methods associated with GameObject. GameObject.Find is a class method, not a member method. Went with ...as it seemed a little cleaner than asking the program to Find the camera. However, this yielded three errors - the same errors I got when I tried GameObject.Find("Main Camera").GetComponent(CameraControllerRevCsharp).cameraNodes.push(myNode); ... a little later. The errors are as follows: 1) Assets/Scripts/NodeControllerRevCsharp.cs(26,42): error CS0119: Expression denotes a 2) Assets/Scripts/NodeControllerRevCsharp.cs(26,29): error CS1502: The best overloaded method match for `UnityEngine.Component.GetComponent(System.Type)' has some invalid arguments 3) Assets/Scripts/NodeControllerRevCsharp.cs(26,29): error CS1503: Argument |
