Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Game Development

Angus Eliott
Angus Eliott
3,793 Points

Unity code error

what is wrong with this code please?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowCamera : MonoBehaviour
{
    [SerializeField]
    private Transform player;
    [SerializeField]
    private Vector3 offset;
    private float cameraFollowspeed = 5f;

}
void Update ()
{}

error code is:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0116  A namespace cannot directly contain members such as fields or methods   Frogs and Logs.CSharp   C:\Users\Angus\Documents\Unity\Frogs and Logs\Assets\Scripts\FollowCamera.cs    13  Active

1 Answer

Steven Parker
Steven Parker
229,786 Points

Just as the error says, that void Update() definition is outside of the FollowCamera class definition. Did you mean to have it inside?