Unity 3D Programming Flashcards
From which menu can you create a new C# script?
Assets
Match the type to the expression. 1. float 2. float or int 3. int 4. other A. 1 B. int someInt; C. “Some text” D. 1.0f
1D, 2A, 3B, 4C
What type is someVariable? float someVariable = 2;
float
What is the result type of the following operation? 2 + 2
int
What is the type of someResult ? float someFloat = 3; int someInt = 3; ??? someResult = someFloat + someInt;
float
Which is the correct suffix for floating point numbers?
f
Why would you choose to wrap some functionality into a method?
To deal with concepts at a higher level.
What is the return type of this function declaration? int DoSomething (string aValue) { }
int
What types of variable does this take? float AnotherMethod(string foo, int bar) { }
string and int
What type does this method return? [omitted] SomeMethod () { return 2.0f + 1.0f; }
float
What in the following would cause an error in Visual Studio? 1. float Square (float numberToSquare) { 2.float square = numberToSquare * numberToSquare * numberToSquare; 3. }
Nothing returned from the method.
What is the correct way to create a 3D vector?
new Vector3 (1.0f, 1.0f, 1.0f)
Which of the following is a valid operation on vectors (assume variables a and b contain Vector3)?
a.magnitude
In the following lines of code, why do we use a dot? Vector3 a = new Vector3(1, 2, 3);
float myX = a.x;
To access the contents x of the a variable
What data is a Vector3 made up of?
3 floats
What is an example of an object?`
A component of a GameObject
Which of the following lines of code correctly gets a render component?
Renderer r = GetComponent( );
What type is returned from the following line of code? GetComponent()
Collider
GetComponent is a function used to find components of a certain type. Where will it search for components?
On the current GameObject.
In which method should you do work relating to Physics?
FixedUpdate( )
Order the following based on order of execution: A. Start() B. Update() C. FixedUpdate() D. LateUpdate()
1A, 2C, 3B, 4D
Which of the following lines of code adds a force to a GameObject?
Rigidbody rb = GetComponent( ); rb.AddForce(new Vector3(0, 0, force));
What is the correct definition of FixedUpdate?
void FixedUpdate( ) { }
What is the time between FixedUpdate calls?
Fixed but configurable
What is returned by ScreenPointToRay?
A Ray.
What are the arguments to ScreenPointToRay?
Screen space coordinates
Which component of the Ray object gives us the vector along which the Ray points?
.direction
Which of the following functions would be best suited to helping debug a Ray that doesn’t seem to be pointing in the correct direction?
Debug.DrawRay( )
How do we get the mouse coordinates in screen space?
Input.mousePosition
When combining two rotations into a new rotation, is the order important?
Yes, always.
Quaternion.Euler() builds a rotation out of 3 seperate rotations about x, y and z axes. Which order are these performed in?
z, x and y
Quaternion.LookRotation() is a…
Method on the class Quaternion.
Suppose I have a Vector3 which defines by rotation called a. Supposing I want to rotate 90 degrees around this axis, how would I construct a Quaternion to do this?
Quaternion rotation = Quaternion.AngleAxis (90, a) ;
How is a Quaternion internally stored?
Using x, y, z and w variables.