So a little background, I’m looking to break into the game development market and I started by taking a few coursea classes. In one such class, we are not focused on programming but rather learning the basics of Unity’s interface. Unfortunately, one of scripts the class provided which is meant to allow for a controllable camera results in the CS0246 Error.
(1,7): error CS0246: The type or namespace name ‘UnityEngine’ could not be found (are you missing a using directive or an assembly reference?)
(4,29): error CS0246: The type or namespace name ‘MonoBehaviour’ could not be found (are you missing a using directive or an assembly reference?)
(6,6): error CS0246: The type or namespace name ‘TooltipAttribute’ could not be found (are you missing a using directive or an assembly reference?)
(7,12): error CS0246: The type or namespace name ‘GameObject’ could not be found (are you missing a using directive or an assembly reference?)
(10,12): error CS0246: The type or namespace name ‘GameObject’ could not be found (are you missing a using directive or an assembly reference?)
- additional 19 errors
It’s probably a simple script but could anyone point me in the right direction when it comes to fixing it? Any help would be HUGELY appreciated
using UnityEngine;
using System.Collections;
public class LookAtTarget : MonoBehaviour {
[Tooltip("This is the object that the script's game object will look at by default")]
public GameObject defaultTarget; // the default target that the camera should look at
[Tooltip("This is the object that the script's game object is currently look at based on the player clicking on a gameObject")]
public GameObject currentTarget; // the target that the camera should look at
// Start happens once at the beginning of playing. This is a great place to setup the behavior for this gameObject
void Start () {
if (defaultTarget == null)
{
defaultTarget = this.gameObject;
Debug.Log ("defaultTarget target not specified. Defaulting to parent GameObject");
}
if (currentTarget == null)
{
currentTarget = this.gameObject;
Debug.Log("currentTarget target not specified. Defaulting to parent GameObject");
}
}
// Update is called once per frame
// For clarity, Update happens constantly as your game is running
void Update()
{
// if primary mouse button is pressed
if (Input.GetMouseButtonDown(0))
{
// determine the ray from the camera to the mousePosition
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// cast a ray to see if it hits any gameObjects
RaycastHit[] hits;
hits = Physics.RaycastAll(ray);
// if there are hits
if (hits.Length>0)
{
// get the first object hit
RaycastHit hit = hits[0];
currentTarget = hit.collider.gameObject;
Debug.Log("defaultTarget changed to "+currentTarget.name);
}
} else if (Input.GetMouseButtonDown(1)) // if the second mouse button is pressed
{
currentTarget = defaultTarget;
Debug.Log("defaultTarget changed to " + currentTarget.name);
}
// if a currentTarget is set, then look at it
if (currentTarget!=null)
{
// transform here refers to the attached gameobject this script is on.
// the LookAt function makes a transform point it's Z axis towards another point in space
// In this case it is pointing towards the target.transform
transform.LookAt(currentTarget.transform);
} else // reset the look at back to the default
{
currentTarget = defaultTarget;
Debug.Log("defaultTarget changed to " + currentTarget.name);
}
}
}