Getting Update and OnGui to talk to each other.

Ok, I’m very new at this (programming and Unity) so bear with me.

I’ve just started a project that has a rails-shooter like element to it. I’ve got a script using OnGUI() to place reticles on the mouse the way I’d like, but I know that I have some physics things I’ll program later that will need mouse position as well. These will almost certainly need to be in Update(). I was wondering if there was a good way of tying the two together so that I only Input.mousePosition once per cycle in Update() lets say and have OnGUI() take the data from there.

Or am I going about this completely the wrong way?

So for clarity my code structure currently looks like this:
"
Def Update()
Input.mousePosition
Code Block A (some code transforming that mouse position)
Some code referring to Code Block A to do things like aim and manuever.

Def OnGui()
Input.mousePosition
Code Block A (some code transforming that mouse position)
Some code referring to Code Block A to do things like place a reticule on the mouse.
"

how do I avoid this duplication of work? Both Update and OnGUI are getting the mouse position and doing the same first few steps to it.

Any help would be greatly appreciated.

Solved my own problem, it was terribly noobish. I hadn’t declared my variables. That’s what gave me the problems with having OnGUI read stuff in Update.

Code now looks like this

Declaring Code Block A variables as public and mostly doubles (interesting how boo uses double instead of float, that threw me for awhile.)

Def Update():
Input.mousePosition
Code Block A
Other code refering to code block A

Def OnGUI():
Code refering to Code block A