Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    100

    2D Unity 4.5 CharcterController SC0116 errors

    I'm stubbing out the code for the character controller and I'm getting a bunch of error CS0116: A namespace can only contain types and namespace declarations.
    I've checked it against the tutorial code and it appears to be the same. Does anyone know what could be causing the error CS0116?

    This is my code:

    using UnityEngine;
    using System.Collections;

    public class CharacterController2D : MonoBehaviour
    {
    private const float SkinWidth = .02f;
    private const int TotalHorizontalRays = 8;
    private const int TotalVerticalRays = 4;

    private static readonly float SlopeLimittangant = Mathf.Tan (75f * Mathf.Deg2Rad);

    public LayerMask PlatformMask;
    public ControllerParameters2D DefaultParameters;

    public ControllerState2D State { get; private set;}

    public void Awake()
    {
    }

    public void AddForce(Vector2 force)
    {
    }

    public void SetForce(Vector2 force)
    {
    }

    public void SetHorizontalForce(float x)
    {
    }

    public void SetVerticalForce(float y)
    {
    }

    public void Jump(
    {
    }

    public void LateUpdate()
    {
    }

    private void Move(Vector2 deltaMovement)
    {
    }

    private void HandlePlatforms()
    {
    }

    private void CalculateRayOrigins()
    {
    }

    private void MoveHorizontally(ref Vector2 deltaMovement)
    {
    }

    private void MoveVertically(ref Vector2 deltaMovement)
    {
    }

    private void HandleVerticalSlope(ref Vector2 deltaMovement)
    {
    }

    private void HorizontalSlope(ref Vector2 deltaMovement, float angle, bool isGoingRight)
    {
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
    }

    public void OnTriggerExit2D(Collider2D other)
    {
    }
    }

  2. #2
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    Hey!

    In the future, please be sure to paste your code between [ code ] and [ /code ] tags (without the spaces) so it shows up a bit nicer on the forum

    I think I did spot your problem, however. The following line:
    Code:
    public void Jump(
    {
    }
    Should instead be:
    Code:
    public void Jump()
    {
    }
    (note the closing paren)

    Does this help?
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

  3. #3
    Join Date
    Sep 2003
    Posts
    100
    Hello Nelson, I was just re-watching the video again. I made the Jump() fix, thanks for that. But, I'm still getting a bunch of CS0116 errors: A namespace can only contain types and namespace declarations. Is this because I'm working in MonoBehaviour? Should I be working in Visual Studio Express?


    Code:
    using UnityEngine;
    using System.Collections;
    
    public class CharacterController2D : MonoBehaviour 
    {
    	private const float SkinWidth = .02f;
    	private const int TotalHorizontalRays = 8;
    	private const int TotalVerticalRays = 4;
    	
    	private static readonly float SlopeLimitTangant = Mathf.Tan(75f * Mathf.Deg2Rad);
    	
    	public LayerMask PlatformMask;
    	public ControllerParameters2D DefaultParameters;
    	
    	public ControllerState2D State { get; private set;}
    	
    	public void Awake()
    	{
    	}
    	
    	public void AddForce(Vector2 force)
    	{
    	}
    	
    	public void SetForce(Vector2 force)
    	{
    	}
    	
    	public void SetHorizontalForce(float x)
    	{
    	}
    	
    	public void SetVerticalForce(float y)
    	{
    	}
    	
    	public void Jump()
    	{
    	}
    	
    	public void LateUpdate()
    	{
    	}
    	
    	private void Move(Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandlePlatforms()
    	{
    	}
    	
    	private void CalculateRayOrigins()
    	{
    	}
    	
    	private void MoveHorizontally(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void MoveVertically(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandleVerticalSlope(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandleHorizontalSlope(ref Vector2 deltaMovement, float angle, bool isGoingRight)
    	{
    	}
    	
    	public void OnTriggerEnter2D(Collider2D other)
    	{
    	}
    	
    	public void OnTriggerExit2D(Collider2D other)
    	{
    	}
    }

  4. #4
    Join Date
    Mar 2004
    Location
    Anacortes, WA
    Posts
    4,168
    Quote Originally Posted by hotsauce View Post
    Hello Nelson, I was just re-watching the video again. I made the Jump() fix, thanks for that. But, I'm still getting a bunch of CS0116 errors: A namespace can only contain types and namespace declarations. Is this because I'm working in MonoBehaviour? Should I be working in Visual Studio Express?


    Code:
    using UnityEngine;
    using System.Collections;
    
    public class CharacterController2D : MonoBehaviour 
    {
    	private const float SkinWidth = .02f;
    	private const int TotalHorizontalRays = 8;
    	private const int TotalVerticalRays = 4;
    	
    	private static readonly float SlopeLimitTangant = Mathf.Tan(75f * Mathf.Deg2Rad);
    	
    	public LayerMask PlatformMask;
    	public ControllerParameters2D DefaultParameters;
    	
    	public ControllerState2D State { get; private set;}
    	
    	public void Awake()
    	{
    	}
    	
    	public void AddForce(Vector2 force)
    	{
    	}
    	
    	public void SetForce(Vector2 force)
    	{
    	}
    	
    	public void SetHorizontalForce(float x)
    	{
    	}
    	
    	public void SetVerticalForce(float y)
    	{
    	}
    	
    	public void Jump()
    	{
    	}
    	
    	public void LateUpdate()
    	{
    	}
    	
    	private void Move(Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandlePlatforms()
    	{
    	}
    	
    	private void CalculateRayOrigins()
    	{
    	}
    	
    	private void MoveHorizontally(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void MoveVertically(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandleVerticalSlope(ref Vector2 deltaMovement)
    	{
    	}
    	
    	private void HandleHorizontalSlope(ref Vector2 deltaMovement, float angle, bool isGoingRight)
    	{
    	}
    	
    	public void OnTriggerEnter2D(Collider2D other)
    	{
    	}
    	
    	public void OnTriggerExit2D(Collider2D other)
    	{
    	}
    }
    Using MonoDevelop or Visual Studio won't make a difference.

    I literally copied and pasted your code into a file on a new project on my machine, and it compiles just fine. I see nothing wrong with this file. It's possible that your errors are coming from a different file, or your Unity project may be a little messed up.

    Could you please post *all* of the output from the console window from Unity (you can ctrl+c them to copy them to your clipboard)?

    Also, try this:
    - Exit Unity
    - Locate your project in Windows Explorer (or Finder if on Mac)
    - Delete the entire "Library" and "Temp" folders (Temp may not exist, that's OK)
    - Start Unity again
    Need any help? Feel free to PM me - or send an email directly to nelson@3dbuzz.com!

  5. #5
    Join Date
    Sep 2003
    Posts
    100
    I deleted the Library and the Temp Scripts. That was the problem. You are awesome!!!!!

    Thanks for all your help Nelson.

    Cheers,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •