A quick and dirty way to make a camera follow a character? Make it a child object…argh.
- used enum & delegate in a practical way.
- Besides simple values and object references, you also store method references in a variable. Such a variable is known as a delegate.
- You define a delegate type as if you're creating a method, except there's no code body. After that, you can use this type to create a delegate variable, to which you can assign any method that matches the type. You can then treat this variable like a method. In fact, you can treat a delegate like a list and add multiple methods to it. All of them will be called when you invoke the variable.
- Events (ah...these get called across multiple scripts):
- For our purposes, an event is a restricted form of a delegate, forced to behave like a list. We could use a regular delegate variable instead and it would work just fine.
- Both events and delegates allow methods to be added and removed from them, viaÂ
myEvent += myMethodÂ and
myEvent -= myMethod. A delegate also allows a direct assignment, viaÂ
myDelegate = myMethod. Doing so replaces whatever other methods had been added to it before. We only want the former functionality and not the latter. By disallowing it altogether, we protect ourselves from a potentially hard to find bug caused by forgetting to write a single
- Cast by placing datatype in parentheses in front of the variable.
- Declare multiple variables of same type by separating with commas in declaration line.
Remember def of static variables: exist independent of object instances. So available to other scripts.
What is Queue?
System.Collections.GenericÂ namespace contains theÂ
QueueÂ class, which can be used to represent a first in, first out queue. By constantly moving the first entry in the queue to the end of it, we effectively get a rotating ring.
QueueÂ is a generic class that can deal with any one type of content. In this case, we useÂ
Queue<Transform>Â to declare a queue ofÂ
- Enqueue(): You can add to the end of the queue by using theÂ
- Dequeue(): Taking out the first item is done with theÂ
- Peek(): Additionally, you can get to the first item without removing it via theÂ
Random.Range has two uses:
- Random.Range(f, f) returns float, inclusive at both ends.
- Random.Range(i, i) returns integer, inclusive, exclusive.
What are physics materials?:
- Physic materials are like regular materials, except they deal with collision instead of visual properties. When objects collide, what happens depends on whether they're made of stone, wood, ice, rubber, or some other substance. You use physic materials to simulate this behavior by configuring friction and bounciness.
Idea for color-based/music theory/runner:
A little bit more in depth explanation of LateUpdate/Physics relationship, it’s not that it’s called last, it’s that it’s called with each discrete physics step!
- The physics engine works by dividing time into little discrete steps â€“ by default 0.02 seconds â€“ during which it moves objects and then checks for collisions and triggers. It keeps doing that in a loop until it has caught up with real time.Â TheÂ
FixedUpdateÂ method works likeÂ
Update, except that it's called once per physics step instead of once per frame. In other words,Â
FixedUpdateÂ is independent of the frame rate. So if you want your code to be independent of the frame rate, put it in this method.
AddForce’s second parameter, I haven’t really used it yet:
AddForceÂ method applies a force to a rigidbody, which might result in an acceleration, which builds up velocity, which results in movement.Â There are actually various ways to use this method, which you control with the second parameter. For example:
- if you want to apply a specific acceleration, regardless of an object's mass, you can use theÂ
- If you want to directly adjust the velocity, you can useÂ
First time using a static class in Unity. Static classes:
- By marking a class as static you require that its contents are static as well. There can't be any nonstatic variables or methods and it cannot be used to create object instances. In other words, a static class is not a blueprint for objects.
There’s aÂ gameObject.active bool.
- The default specular shader works like the diffuse shader, except that it also has a specular color and a shininess value. The shader uses these to add a highlight to the visuals.Â We use this shader forÂ BoosterÂ because it results in more vivid color changes while it rotates.