In my scene I’ve created a Plane which I’m going to use for my npc’s to work out when they should fly (as if they are in the same area as the plane it means they are not on anything solid and so need to fly to saftey).
therefore I need to stop the player being able to collide with the plane which I’ve done so here in the start function
Physics.IgnoreCollision(CollisionFlyingCheck.collider, collider);
CollisionFlyingCheck is assigned as such :
public Transform CollisionFlyingCheck;
this all works fine in my game however this error keeps popping up and I want to know what have I done wrong as its annoying me :P. The error is strange because I have assigned CollisionFlyingCheck the plane object in the inspector.
UnassignedReferenceException: The variable CollisionFlyingCheck of ‘s_Player’ has not been assigned.
You probably need to assign the CollisionFlyingCheck variable of the s_Player script in the inspector.
s_Player.Start () (at Assets/Scripts/s_Player.cs:17)
Edit I’ll post the entire of my s_Player script incase people want a closer look.
public class s_Player : MonoBehaviour
{
public float playerSpeed; //let Unity declare its value.
private Transform playerTransform;
public Transform CollisionFlyingCheck;
//Use this for initalization
void Start()
{
//We do this so the program only has to look up transform once rather then everytime it is called.
playerTransform = transform;
Physics.IgnoreCollision(CollisionFlyingCheck.collider, collider); //CollisionFlyingCheck is not suppose to block people from falling, only there so npcs know when to fly
}
// Update is called once per frame
void Update ()
{
//Let the player jump: while space bar is held disable all gravity otherwise the robot can't fly
if(Input.GetButton("Jump")){
playerTransform.Translate(Vector3.up * playerSpeed * Time.deltaTime);
rigidbody.useGravity = false;
}
if(Input.GetButtonUp("Jump"))
rigidbody.useGravity = true;
//Move the player: use the translate function so it doesn't look like the player is teleporting to the new position.
if(Input.GetButton("Vertical"))
playerTransform.Translate(Vector3.forward * Input.GetAxis("Vertical") * playerSpeed * Time.deltaTime);
if(Input.GetButton("Horizontal"))
playerTransform.Translate(Vector3.right * Input.GetAxis("Horizontal") * playerSpeed * Time.deltaTime);
//adjust player if he goes over boundaries.
if(playerTransform.position.y <= -15.5f)
//the player has fallen off the screen so lets destroy it
Destroy(this.gameObject);
}
}