Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    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:
    16,149
    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. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,793
  5. IrrisWhatts

    IrrisWhatts

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