I don’t really know about C#sharp. Could I get help?
This is my program. I’m trying to get the user input to control the player.
I cant get the RigidBody component.
using UnityEngine;
using System.Collections;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, zMin, zMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
First you should create a variable of type Rigidbody and in the Awake you set that variable to the actual component, so that you can use that variable to access the rigidbody later.
Example: (not tested!)
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
private Rigidbody rb;
void Awake(){
rb = gameObject.GetComponent<Rigidbody>();
}
private void Example() {
rb.velocity = some value;
}
}
Also have a look at Unity - Scripting API: Rigidbody if you haven’t already. there are other ways to move the object instead of changing the velocity directly.