Unity keeps rejecting my code, even when there are no errors
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();
}
}
Answer by SolunaGD · Jun 02, 2016 at 12:55 AM
Figures! I found the answer myself.... after I posted here and asked various people for help! As I looked into unity I saw that there is no UI object that is referenced for public Text scoredis;
So what I had to do was drag the UI element into the variable scoredis in unity. The entire time scoredis had no object so as I was trying to update the score value, I was updating nothing. I hope this helps anyone else.
Your answer
Follow this Question
Related Questions
"The associated script cannot be loaded" 0 Answers
Menu object not responding 0 Answers
"The associated script cannot be loaded." 0 Answers
WHAT IS WRONG WITH THIS CODE? 0 Answers
Can't add Orbital script - "The script needs to derive from MonoBehaviour!" 0 Answers