- Home /
Quick C# Question - Variables in Other Scripts
'Nother quick one: I have a script, "CameraControlScript", attached to the Main Camera that locks on to a Transform called 'target'.
Now I am trying to make an object assign itself as the target for CameraControlScript. I currently have:
Camera.main.GetComponent<CameraControlScript>.target = transform;
But this throws
error CS0119: Expression denotes a `method group', where a `variable', `value' or `type' was expected
I'm missing another C# gotcha... Can someone help this hapless Javascripter out?
Thank you so much!
Answer by clunk47 · Dec 28, 2012 at 01:14 AM
Camera.main.GetComponent<CameraControlScript>().target = transform;
You forgot some parenthises.
Hah, thank you. I figured it out the second I posted the question. Always happens...
Answer by SergeantBiscuits · Dec 28, 2012 at 01:15 AM
D'oh! Forgot the parentheses.
Needs to be:
Camera.main.GetComponent<CameraControlScript>().target = transform;
Crazy C#!
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Look at object when it is in the range of the player 0 Answers
Multiple Cars not working 1 Answer
Unity's mouse look causing movement issues 1 Answer
Smooth out character movement? 4 Answers