Unity Default Script

When you first open unity and create a new C# script you will see something like this. It is recommended to install Visual Studio for a better experience


using UnityEngine;
using System.Collections;
            
public class MainPlayer : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
}

Creating Rigidbody

When you first you first create a 3D or 2D object, you have the ability to add components. Here we can add a rigidbody, collider, and a the script which we have created

Play

What you should see when you press play is the object you have created fall until it is no longer in view. Now copy the code below into the script you have created earlier, making sure the script is also placed on your GameObject


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Object : MonoBehaviour
{
    public Rigidbody RB;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        RB.AddForce(new Vector3(0, 100, 0));
    }
}

Play, Again

Before pressing play make sure to drag the RigidBody component into the RB slot which we have created