Error Message: UnassignedReferenceException: The variable groundCheckTransform of Player has not been assigned. You probably need to assign the groundCheckTransform variable of the Player script in the inspector. UnityEngine.Transform.get_position () (at :0) Player.FixedUpdate () (at Assets/Scripts/Player.cs:36)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
private bool jumpKeyPressed;
private float horizontalMovement;
private Rigidbody rigidcomponet;
public int jforce = 7;
public int movementspeed = 2;
public Transform groundCheckTransform=null;
// Start is called before the first frame update
void Start()
{
rigidcomponet = GetComponent <Rigidbody>();
}
// Update is called once per frame
void Update()
{
// Check if space clicked down
if (Input.GetKeyDown(KeyCode.Space))
{
jumpKeyPressed = true;
}
horizontalMovement = Input.GetAxis("Horizontal");
}
// Updates every physics update. Aka 100 times per second
void FixedUpdate()
{
rigidcomponet.velocity = new Vector3(0,rigidcomponet.velocity.y,horizontalMovement*movementspeed);
if (Physics.OverlapSphere(groundCheckTransform.position, 0.1f).Length == 0)
{
return;
}
if (jumpKeyPressed)
{
rigidcomponet.AddForce(Vector3.up * jforce, ForceMode.VelocityChange);
jumpKeyPressed=false;
}
}
}