Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Crashing ingame using portals, but in Unity, it works fine

Discussion in 'Scripting' started by Hyrazan, May 27, 2023.

  1. Hyrazan

    Hyrazan

    Joined:
    Apr 22, 2023
    Posts:
    1
    When I Build the Unity game, whenever you step into a portal, it just.. crashes. The same could not be said when inside the Editor. I have multiple of these portals, but they still work fine inside the Editor, as mentioned. Can someone identify the problem?
    Code:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Tp : MonoBehaviour
    6. {
    7.     [SerializeField] Transform tp;
    8.  
    9.     [SerializeField] GameObject player;
    10.     private void OnTriggerEnter(Collider other)
    11.     {
    12.         StartCoroutine(Teleport());
    13.     }
    14.     IEnumerator Teleport()
    15.     {
    16.         yield return new WaitForSeconds(0);
    17.         player.transform.position = new Vector3(
    18.             tp.transform.position.x,
    19.             tp.transform.position.y,
    20.             tp.transform.position.z
    21.         );
    22.     }
    23.    
    24. }
    25.