unt Flashcards
A raycast is
a laser beam with a length, it can create collisions. Often used to detect which game object a user clicked on.
To get a position of a mouse in world space, type
Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
A scriptable object is a
script you save into the assets folder.
The variables and functions defined inside are accessible in all scenes and persist between pressing play.
Note: They do not persist in when the real end player closes the game.
One use case for a scriptable object script is to hold one global variable in each script because
it allows you to drag a reference to that script into a prefabs monobehavior script so the rest of the script can get the value from there a unified place.
This happens by telling unity instead of your public variable being a float, it is actually of type “MyScriptableObjectScriptName”, and then inside the prefabs monobehavior script, you will call MyScriptableObjectScriptNameInstance.Value to get the value stored inside the scriptable object script.
This means that the scriptable object script will need to define the Value variable so it can later be called inside the monobehavior.
Note: This is only useful for global variables, not variables that are unique to a particular instance. ie instance’s health bar
One use case for a scriptable object script is to define event type like GameEventType1 and
this event type will have a list of subscribers, and a loop to call a function on all the subscribers whenever this event is raised. e.g. I game object and I am die, I raise a death event with a parameter of myself, and then in response, all the listeners will call destroy on themselves if their ID is the same as the parameter.
The GameEvent scriptable object is just a unique event type (channel) that will store its own list of subscribers.
The GameEventListener monobehavior will have dragged in the type of event GameEvent it is listening to and it will dragged in the function call defined in the inspector for it to invoke in response to the event.
The function response should live where.
If the function you are calling is dragged into the inspector into a UnityAction, then to call it you call that variableName.invoke()
So each scriptable object event is a unique type of event, and inside
If you have a public function, you
Ok, so all the listeners have an OnEventRaised function defined, so when the GameEventType1 event is raised, it calls OnEventRaised on all the listeners.
The reason Unite Austin 2017 video uses Response.invoke() is because he wants to be able to drag in the function call to invoke rather than define it in the code repeatedly.
Then on the prefab you will have a GameEventListener monobehavior script and it will take take in the inspector a reference to the GameEventType1 and the function it needs to call in response.
In c#, before you write the function name, you must
write the return type
ie void MyFunc() int MyFunc()
In c#, a static field if changed in one class instance will
change in all of the instances
in c# the delegate keyword denotes
a function with no body that will be overridden