Object Class
Object Class
Object Class
Singleton?
If you don’t know what a Singleton is, you probably should. A Singleton is a script
that cannot be an Instanced or ‘Duplicated’. It is, well… Single.
I recommend using Singletons for things that do not need to be copied multiple
times during a game. Such as an Inventory System. Typically, the player only needs
one Inventory, so we don’t want to call Instances of it, we only want one. And when
we call it, we want to make sure it doesn’t get duplicated.
Define a Delegate and the method that gets called when it fires…
The delgate called ‘OnClickEvent’ passes a ‘GameObject’ that we can use to define
what game object it came from. Then, we defined an ‘event’ OnClick that gets called
when the delegate is called.
Now, in the same script, we need to call the delegate and pass it our GameObject.
I’ve done this through a Raycast…
As you can see, if the Ray has contact an Object in the scene and we Left-Mouse-Click,
we call the event and pass the GameObject.
The last thing we must do is reference the delegate from our other scripts that are
listening to the call. For this I’ve created a class called ‘GoldPile’.
Static batching allows the engine to reduce draw calls for geometry of any size
provided it shares the same material, and does not move. It is often more efficient
than dynamic batching (it does not transform vertices on the CPU), but it uses more
memory.
Difference between Start and Awake Unity Events
Quoting from the docs:
The difference between Awake and Start is that Start is only called if the
script instance is enabled. This allows you to delay any initialization code,
until it is really needed. Awake is always called before any Start functions.
This allows you to order initialization of scripts.
•Update
•LateUpdate
•FixedUpdate
LateUpdate is called after all Update functions have been called. This is
useful to order script execution. For example a follow camera should always
be implemented in LateUpdate because it tracks objects that might have
moved inside Update.
Also note that LateUpdate is called after animations are applied - this means you can
implement procedural animation in LateUpdate which modifies the pose sampled by
the animation system.
FixedUpdate is called every fixed framerate frame, if the MonoBehaviour is
enabled. FixedUpdate should be used instead of Update when dealing with
Rigidbody. For example when adding a force to a rigidbody, you have to
apply the force every fixed frame inside FixedUpdate instead of every frame
inside Update.
I hope that helps. You can read more about overridable functions on the scripting
reference page for MonoBehaviour.
Add convex mesh colliders to them both. Add a rigidbody to at least one of them.
Difference between Static and Dynamic Batching.
public class B
:A
{
// must implement, since it is not abstract
public override string sayHello() { return "Hello from B"; }
}
Interface is more like a protocol. A list of methods that a class implementing that
interface musthave. But they don't do anything. They have just method prototypes.
public interface A
{
string sayHi(); // no implementation (code) allowed
string sayHello(); // no implementation (code) allowed
}
public class B
:A
{
// must implement both methods
string sayHi() { return "hi"; }
string sayHello() { return "hello"; }
}
2.
Difference between overloading and overriding
Overloading occurs when two or more methods in one class have the same method
name but different parameters. Overriding means having two methods with the same
method name and parameters (i.e., method signature). One of the methods isin the parent
class and the other is in the child class.
(1) The size of the arrays is fixed: So we must know the upper limit on the number of
elements in advance. Also, generally, the allocated memory is equal to the upper limit
irrespective of the usage, and in practical uses, upper limit is rarely reached.
(2) Inserting a new element in an array of elements is expensive, because room has to be
created for the new elements and to create room existing elements have to shifted.
Deletion is also expensive with arrays until unless some special techniques are used. For
1)Dynamic size
2) Ease of insertion/deletion
1) Random access is not allowed. We have to access elements sequentially starting from the
2) Extra memory space for a pointer is required with each element of the list.
3) Arrays have better cache locality that can make a pretty big difference in performance.
What is an Interface?
An interface, on the other hand, is not a class which contains only the
signature of functionality. It’s a pattern with no implementation.
Conceptually speaking, it’s just the definition of methods which contains
only the declaration of members. It’s an empty shell which does not
contain the implementation of its members. It’s like an abstract base
class which only contains abstract members such as methods, events,
indexers, properties, etc. It cannot be instantiated directly and its
members can be implemented by any class. Additionally, multiple
interfaces can be implemented by a class, however, a class can only
inherit a single class.
Delegate :
A Delegate is a reference pointer to a method. It allows us to treat method as
a variable and pass method as a variable for a callback. When it get called , it
notifies all methods that reference the delegate. The basic idea behind them
is exactly the same as a subscription magazine. Anyone can subscribe to the
service and they will receive the update at the right time automatically.
I know at this time everything seems very confusing, just wait everything will
be clear when start doing coding.
Vertex Shader vs Surface Shader
The Fragment Shader is a program that runs on each and every pixel that object
occupies on-screen, and is usually used to calculate and output the color of each pixel.
Usually there are millions of pixels on the screen, and the fragment shaders are
executed for all of them! Optimizing fragment shaders is quite an important part of
overall game performance work.