- Home /
Question by
jimkiller12 · Jan 25, 2012 at 05:06 AM ·
c#
C# Unity 3D: LookAt.cs Help please
I'm having trouble trying to get this to work.
using UnityEngine;
using System.Collections;
public class LookAt : MonoBehaviour
public Transform target;
void Update()
{
transform.LookAt(target.transform);
}
Getting this error when running: LookAt.cs(6,7): error CS1031: Type expected
Any help would be appreciated.
Comment
Best Answer
Answer by Lo0NuhtiK · Jan 25, 2012 at 05:09 AM
You need to enclose the rest of your code inside the MonoBehaviour class...
public class LookAt : MonoBehaviour { //<--!!add curly-brace
//whatever other code
} //<--!!add curly-brace
Thanks for the help, but i added the Braces but im still getting the same error
Shouldn't. I just pasted your code in a c# script after reading your comment, added the brackets, and get no errors.
using UnityEngine;
using System.Collections;
public class LookAt : $$anonymous$$onoBehaviour {
public Transform target;
void Update()
{
transform.LookAt(target.transform);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613063352im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
C# Unity 3D Lock Rotation but allow Rotation of Parent Object 1 Answer
Pushing More GUI Clips Than Popping 0 Answers
Multiple Cars not working 1 Answer