error code assets won't solve

Assets/Mouseclick.cs(3,19): error CS0116: A namespace can only contain types and namespace declarations

i get this error message but i don’t know whats wrong. could someone help me with this?

code:

using UnityEngine;
using System.Collections;
public GameObject Doel;

public class Mouseclick : MonoBehaviour 
{
	public bool isClicked = false;
	public string name = "Doel";
	public GameObject Doel;

	public void Start()
	{
		if(GameObject.GetComponent(Collider) == null)
		GameObject.AddComponent(typeof(BoxCollider));
	}
		
	public void OnMouseDown()
	{
		isClicked = true;
	}
		
	public void OnMouseUp()
	{
		isClicked = false;
	}

	public void OnGUI()
	{
		if(isClicked)
		GUI.Label(new Rect(5,5,400,100), "This is " + this.name);
	}
}

Okay, so I’m posting this as answer so other members can easily see the solution, which I hope this is :slight_smile: I editted your code a little and you must now attach it to the GameObject which are you clicking on, if not, then the OnMouseDown and OnMouseUp events are not fired. Just to answer the last error you commented; the syntax you’re using to get/add the component is not correct. The correct syntax would be GameObject.GetComponent();

using UnityEngine;
using System.Collections;

public class Mouseclick : MonoBehaviour 
{
	public bool isClicked = false;
	// Commented these two scripts out
	// Attach this script to the Doel GameObject instead
//	public string name = "Doel";
//	public GameObject Doel;
	
	public void Start()
	{
		// Now looking at the GameObject that this script is attached to
		if(gameObject.GetComponent<Collider> () == null)
			gameObject.AddComponent<BoxCollider> ();
	}
	
	public void OnMouseDown()
	{
		isClicked = true;
	}
	
	public void OnMouseUp()
	{
		isClicked = false;
	}
	
	public void OnGUI()
	{
		// this.name will still work as you'll just get the gameObject's name 
		if(isClicked)
			GUI.Label(new Rect(5,5,400,100), "This is " + this.name);
	}
}