So, I am a novice making a game in unity, however, after fixing a few errors, Unity now refuses to load my script C# because it is saying “The associated script cannot be loaded. Please fix any compiler errors and assign a valid script.” I cannot find any errors in my script however, so can you please help? (This script is meant to control the player’s movement, and keep track of score)
EDIT: Not sure if this helps, but an exception called System.NullReferenceException was also thrown
Another edit : The compiler gives no errors
Here is my code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class Movement : MonoBehaviour
{
private int points;
private Rigidbody rb;
public float speed;
public Text scoredis;
void Start()
{
rb = GetComponent<Rigidbody>();
points = 0;
PointDisplay();
}
void FixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Pickup"))
{
other.gameObject.SetActive(false);
++points;
PointDisplay();
}
}
void PointDisplay()
{
scoredis.text = "Score: " + points.ToString();
}
}