Search Unity

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:
    21,154
    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. Deleted User

    Deleted User

    Guest

  5. IrrisWhatts

    IrrisWhatts

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