No Clue Why It Wont Compile

I am following a tutorial to familiarize myself with Unity and when I try to compile my script I get this error message:
Error CS0246: The type or namespace name `UnityEngine’ could not be found. Are you missing a using directive or an assembly reference?

It is pointing to line 1 where it simply has using UnityEngine;

It makes no sense that it is pointing to something that is already put there so I must be missing something. I am putting the entire code below in the hopes that someone can tell me what I am missing. I have come across this with every single tutorial I have tried to follow now and am getting tired of not being able to get passed this one issue. Any help would be greatly appreciated.

I am writing in C# and this is a simple script that is going to grow into a cannon that will fire a cannonball but for now is to make the camera move around the scene.

using UnityEngine;
using System.Collections;

public class Cannon : MonoBehaviour {
	
	// Update is called once per frame
	void LateUpdate () 
	{
		float x = Input.GetAxis("Mouse X") * 2;
		float y = Input.GetAxis("Mouse Y");
		
		//vertical tilting
		float yClampled = transform.eulerAngles.x + y;
		transform.rotation = Quaternion.Euler(yClamped, transform.eulerAngles.y, transform.eulerAngles.z);
		
		//horizontal orbiting
		transform.RotateAround(new Vector3(0, 3, 0), Vector3.up, x);
	}
	


}

Thanks

I want to thank you all for helping out. I managed to get it all working as it was supposed to. I decided to start with a fresh project (mine was small and didn’t hurt to do so) and I went through the simple operations of Assets-> Create-> C# and named the file. From there I moved the script into the scripts folder and then attached it to the object I wanted it on. Then I opened the script and edited it and then just hit CMD+S and then went back and tested the game. I still got warnings but I was able to trouble shoot those and what I was forgetting to do was put my projectile prefab into the Inspector portion of the script. Once I did that it seemed to run perfectly. So if anyone else out there is running into similar issues then I hope this helps you out also. Again, I want to thank you guys for helping my and I am going to post the final code below just so it is there if anyone wants to make a projectile that shoots from their camera (or whatever) like the tutorial I was following.

Main Camera Script is titled Cannon

using UnityEngine;

using System.Collections;



public class Cannon : MonoBehaviour {
	public GameObject projectilePrefab;
	
	void LateUpdate() {
		float x = Input.GetAxis("Mouse X") * 2;
		float y = -Input.GetAxis("Mouse Y");
		
		// vertical tilting
		float yClamped = transform.eulerAngles.x + y;
		transform.rotation = Quaternion.Euler(yClamped, transform.eulerAngles.y, transform.eulerAngles.z);
		
		// horizontal orbiting
		transform.RotateAround(new Vector3(0, 3, 0), Vector3.up, x);
	}

	
	void FixedUpdate () {
		if (Input.GetButtonDown("Fire1")) {
			GameObject projectile = Instantiate(projectilePrefab, transform.position, transform.rotation) as GameObject;
			projectile.rigidbody.AddRelativeForce(new Vector3(0, 200, 500));
		}
	}
	
	
	
	
	
}

Cannonball script is cleverly titled Cannonball

using UnityEngine;
using System.Collections;

public class Cannonball : MonoBehaviour {
	public GameObject projectilePrefab;

	void FixedUpdate () {
		if (Input.GetButtonDown("Fire1")) {
			GameObject projectile = Instantiate(projectilePrefab, transform.position, transform.rotation) as GameObject;
			projectile.rigidbody.AddRelativeForce(new Vector3(0, 200, 500));
		}
	}
}

Now I am just messing with the numbers and then going to be making some additions to grow this project into something bigger in order to keep learning.

Thanks

try changing the yclamped in the Euler to yClampled cause that’s the only error that showed up on mine.you forgot an l that’s all or try changeing your float to yClamped ether way should work.

Are you trying to compile in your editor? if so, don’t, just save it in the assets directory of your unity project, then it loads IN unity

Yea it’s probably because your project has no reference to UnityEngine.dll. Easiest way is to create and open the script from Unity and let Unity build your code project. If not you actually have to set the reference to the .dll’s up yourself.

Just on another note, though. Don’t use transform.something. Every time you’re doing that it’s actually doing a GetComponent call. Instead cache the transform in Start, once, and then use that.

That’s not true, though. The .transform property is cached (not a GetComponent call), and while manually caching it yourself is a little faster, it’s usually not worth the bother.

–Eric

Thanks for all the responses so far. So to make sure I got this right so far, Make sure that I am creating the script from inside Unity first and then editing it in Mono-Develop and then compiling it in Unity? So in other words make sure that the object I want the script to be attached, I go and add the script component and then open it and put in what I want. Then come back to unity and run the script from there?

I hate to sound like such a noob but I only spent 1 month in Unity in school and the rest of the time we were working in UDK so I am only now trying to get back into Unity. I will give it a shot and see if that works for me and let you all know.

As for the .transform well I will have to get a little more knowledge on the subject before I am able to figure out other ways to write out code. I do appreciate all of you helping out thus far.

When you save a script it compiles in Unity automatically.

–Eric