Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Teleport CS0116 Error

Discussion in 'Getting Started' started by TYREDSAUCE, Jul 4, 2021.

  1. TYREDSAUCE

    TYREDSAUCE

    Joined:
    Feb 14, 2021
    Posts:
    1
    So I'm trying to get it so that when a player walks up to a door they can press E and it will teleport them to the inside. But I'm getting the error of "Assets\EnterScript.cs(11,10): error CS0116: A namespace cannot directly contain members such as fields or methods"
    Here's my code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class EnterScript : MonoBehaviour
    6. {
    7.     public Transform TeleportTarget;
    8.     public GameObject Player;
    9.  
    10. }
    11.     void OnTriggerEnter()
    12.     {
    13.     if (Input.GetKeyDown(KeyCode.E))
    14.         Player.transform.position = TeleportTarget.transform.position;
    15.         Debug.Log("Ha Pasado");
    16.  
    17.     }
    18.  
    19.  
    I'm not sure what's going on.
     
  2. Valjuin

    Valjuin

    Joined:
    May 22, 2019
    Posts:
    481