Learn C# Scripting for Unity (Moving GameObject)




The following instructions are meant to be used for the 3D environnement, if you are working on 2d , you just need to use rigidbody2d and vector2 instead of rigidbody and vector3 respectively.

For rigidbody2d you may need to add this before starting you class:

[RequireComponent(typeof(Rigidbody2D))]


In this section you will learn :

1 - Adding force to a gameObject to let it jump

2 - Move the object forward 

To do this you need to attach a rigidbody component to you game object , create a new c sharp script and type the following :



You must choose between jumping or moving, if not your code is kid of a mess , so try to comment the second line inside the if statement .

Save it then back to unity and press run , press space button  and see your code results .

Congrats , you have just learnt how to make objects move .

Comments

Popular Posts