I finished the Roll A Ball Tutorial, and everything works correctly when I play it in Unity. I get errors only when building. From researching this issue, I can only find issues with matching the name of the file or making sure “MonoBehaviour” has a “u” in it.
Errors in console:
One of my scripts is:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class SphereController:MonoBehaviour {
public float speed;
private Rigidbody rb;
private int count;
public Text countText;
public Text winText;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText();
winText.text = "";
}
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);
count = count + 1;
SetCountText();
}
}
void SetCountText()
{
countText.text = "Count: " + count.ToString ();
if (count >= 16) {
winText.text = "You Win!";
}
}
}
That’s not supposed to be happening! It seems like Unity can’t find Unity when it’s making a build.
What’s your Unity version, and what’s your build target? It might be that there’s something strange in the build setup. Open the build menu, and make sure that the build target set is something you support - so Windows 64 bit if you’re on a Windows 64 bit machine. If you have an older version of Unity, it was possible to not download build support for your own machine, which caused all kinds of nonsense.
Same Error Message for Roll a Ball
Error Message: Assets/Scripts/CameraController.cs(5,33): error CS0246: The type or namespace name `MonoBehaviour’ could not be found. Are you missing an assembly reference?
Version of Unity: 2017.2.0f3 Personal
Received message related to all scripts in Roll a Ball Tutorial
Received similar message when I tried to build another game, with a new script.
Projects are on Desktop
Windows operating system; new 2017 HP Omen Laptop
Using MonoDevelop. However, in the project folder I notice that each project I’ve created, has a Microsoft Visual Studio file; its file name is the same as the project (i.e. Roll A Ball).