“Private” means It won’t appear in the inspector
Yes, though you can make private variables appear in the inspector if you need to.
and the only way to reach this data is by directly editing it in the script where it is found?
Rigidbody rb means that rb is a variable linked to the game object Rigidbody?
No. Rigidbody rb means that your script has a variable named rb, of the type Rigidbody, and this variable may be uninitialized, or hold a null value, or hold a rigidbody that belongs to your script’s gameobject, or hold a rigidbody that belongs to another gameobject (if it holds a rigidbody that doesn’t belong to any gameobject you probably screwed something up). To link it to the gameobject’s rigidbody, you’ll either need to link the rigidbody to your script in the inspector, or make a new one and get a reference to it with
this.rb = someGameObject.AddComponent<Rigidbody>() if someGameObject is a gameobject that doesn’t already have a rigidbody (you can use
this.gameObject to get a reference to the script’s own gameobject).
then the diference between “Rigidbody rb;” and “int count;” is
Rigidbody is a reference type and int is a value type. You can read up on the difference between value types and reference types by googling them, the details aren’t important here. Rigidbody is also a UnityEngine.Component, meaning you can add it as a component to a gameobject, and link it to another Component’s field in the inspector if you need to. As far as your script’s concerned, though, Rigidbody is just another class.
Now, all those public fields that you declare in your monobehaviour and set in the inspector, what happens to those is that when the game starts up, and the scene with your gameobject loads up, and the gameobject initializes, and all instances of your classes (your scripts) initialize, Unity fills in all those public fields with the values and references that you set in the inspector in the editor, so your script can fiddle with them.
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
Also I’d like to know what the “new” means in this code.
You’re creating a new instance of a Vector3 struct. You’re also assigning it to the Vector3 variable you just declared.
The whole code means that the variable movement will recieve a new x,y,z, right?
If so why not make it without the “new” expression?
Vector3 movement = someOtherVectorThatAlreadyExists;? You could do that. Additionally since Vector3s are structs and structs are value types, this will just copy the values, and you’ll be dealing with two different vectors now (that happen to have the same value).