Posts

Showing posts with the label get component

GetComponent usage

 public class startingForce : MonoBehaviour {     public float yval;     Rigidbody thisRigidBody;     // Start is called before the first frame update     void Start()     {         thisRigidBody = GetComponent<Rigidbody>();         thisRigidBody.AddRelativeForce(0,yval,0);     }     // Update is called once per frame     void Update()     {              } } Like this! ^ here we use GetComponent to look for the Rigidbody component attached to the same GameObject Note the use of < to surround > the component type and how it is followed by the ( ) <-something I keep forgetting. Also note how we make a variable of the same component type equal to it, so we can then refer to it.