Hey, so I’m doing an online gamedev course and I’m having some trouble understanding a bit of code. I numbered each line of code and the comments/questions are below with the corresponding number.
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
1 GameObject Instance = Instantiate(ballPrefab);
2 Rigidbody rb = Instance.GetComponent<Rigidbody>();
3 rb.velocity = Vector3.left*speed;
}
-
So on this line, Instantiate creates a ball prefab and assigns it to the GameObject Instance, correct?
-
This takes the ball prefab that was assigned the name Instance and assigns it a rigidbody, or is it just creating a rigidbody to be assigned later on? This line is where I’m most confused.
-
Takes the rigidbody object and assigns it a velocity.