Code Explained: Creating Balls - Task 2 Part 2

This is the code we used to create balls by pressing a button.


The variable 'm_prefab' has been declared in the public class as a gameObject meaning that a new game object has been created that can be used in Unity.

3D vectors are structure that are used throughout Unity to pass 3D positions and directions around. It  contains functions for doing common vector operations.

Vector3 -  Creates a new vector with given x, y, z components.

Random.Range - Returns a random float number between and min [inclusive] and max [inclusive]. This range is between -1f and 1f and is the same for the vectors x, y and z value components.

Quaternion - Constructs new Quaternion with given x,y,z,w components.

Instantiate - Clones the object original and returns the clone.

To summerise, this code creates clones of the ball prefab and spawns them randomly.


Bibliography & References
[1] https://docs.unity3d.com/ScriptReference/Random.Range.html
[2] https://docs.unity3d.com/ScriptReference/Vector3.html
[3] https://docs.unity3d.com/ScriptReference/Quaternion.html
[4] https://docs.unity3d.com/ScriptReference/GameObject.html

Comments

Popular posts from this blog

Logo Design

Bootstrap Template