New to Coding
Hey guys, so I have written a player movement/camera controller however I ended up messing smoething up and I do know the fix already. Basically what I need help with is learning how to rewrite this portion of my code to make it valid and working. Here is my script;
The issue is I assigned a local variable CameraController controller in the Awake() method, the field CameraController cameraController; on class level will not be given a value but I'm unsure on how I would rewrite it to get my character moving. Let me make it clear that I don't just want the answer or anything like that, if possible I would like someone to actually explain the steps so I can learn how to solve my mistake and prevent it in the future.
7 Replies
Firstly, you're way more likely to get better help in #game-dev or $unity
Secondly, you're setting
Camera.main.GetComponent<CameraController>()
to a variable called controller
inside Awake()
. If you want to set the field, you should set cameraController
instead.Ohhh, I see, so would this be correct?
Also, I will most certainly join that discord
Well, you're still declaring a variable here, but now it has the same name as your field.
If you want to assign the field, you just use
cameraController = ...;
without the typeOhhh so
It works now, thanks so much you're a big help
I greatly appreciate the responses and the patience, thank you so much
yep