basic code Flashcards
1
Q
How to move an object?
A
transform.Translate(Vector3.forward * speed* Time.deltaTime);
speed is the float variable.
2
Q
How to rotate an object?
A
transform.Rotate(Vector3.up * speed * Time.deltaTime);
speed is the float variable.
3
Q
add velocity to the rigibody?
A
GetComponent().velocity = new Vector3(0, 10, 0);
x axis, Y axis, Z axis
4
Q
How to detect a collision
A
void OnCollisionEnter(Collision col) { if(col.gameObject.name == "Player(Clone)"){ score += 100; print(score); }
}
the if statement inside checks if the object collided with is a certain tag name. the col can be named anything.
5
Q
Is it better on performance to find a gameobject by name or tag. When should this be called?
A
Finding a game object with by Tag is better for performance and it should be done in the start and awake function.