In my main Unity script I access other game objects frequenty, e.g. the camera. Since I do not want to call GameObject.Find("Main Camera")
in every Update()
, I want to keep a reference to the instance as a class-local variable.
However when I try
import UnityEngine
class PlayerBehaviour (MonoBehaviour):
main_camera as GameObject = GameObject.Find("Main Camera")
I get “UnityException: You are not allowed to call this function when declaring a variable.
Move it to the line after without a variable declaration.”
When I move this to Start()
import UnityEngine
class PlayerBehaviour (MonoBehaviour):
def Start ():
main_camera = GameObject.Find("Main Camera")
return
I get “Assets/PlayerBehaviour.boo(25,9): BCE0005: Unknown identifier: ‘main_camera’.”
How can I assign a local variable to the instance of another GameObject at initalisation, using Boo?
EDIT: The camera is just an example. I am looking for a Boo technique to cache a reference to any GameObject.