how to add force scripting unity code example
Example 1: Rigidbody.addforce
using UnityEngine;public class ExampleClass : MonoBehaviour
{
public float thrust = 1.0f;
public Rigidbody rb; void Start()
{
rb = GetComponent<Rigidbody>();
rb.AddForce(0, 0, thrust, ForceMode.Impulse);
}
}
Example 2: rb.addforce 3d c#
rb.AddForce(0, 0, 5 * time.deltaTime);
// time.deltaTime is optional