Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

please help

Discussion in 'Getting Started' started by jacksandison00, Jul 12, 2020.

  1. jacksandison00

    jacksandison00

    Joined:
    Jul 12, 2020
    Posts:
    5
    Assets\PlayerCollision.cs(6,6): error CS0116: A namespace cannot directly contain members such as fields or methods
    how do i fix
    this is my code im new to coding

    using UnityEngine;
    public class PlayerCollision : MonoBehaviour {
    public PlayerMovement movement;
    }
    void OnCollisionEnter(Collision collisionInfo)
    {
    UnityEngine.Debug.Log(collisioninfo.collider.name);
    {
    UnityEngine.Debug.Log("we hit an obstacle");
    }
    {
    if (collisionInfo.collider.tag) ("obstacle");
    }
    }
     
  2. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    20,128
    Fourth line. You're closing the definition of the class with the closing curly brace before you finish defining it.
     
  3. jacksandison00

    jacksandison00

    Joined:
    Jul 12, 2020
    Posts:
    5
    thanks for the help but could i have an exaple
     
  4. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
  5. IrrisWhatts

    IrrisWhatts

    Joined:
    Aug 17, 2020
    Posts:
    16
    Hi, I hope you solved your problem!