Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Sprite appearing in scene but not in game

Discussion in 'Getting Started' started by Nomski, May 13, 2024.

  1. Nomski

    Nomski

    Joined:
    Apr 13, 2024
    Posts:
    8
    Hey! I am working on this game, where the player travels between rooms and I've come across a problem.
    After re-enabling the sprites (for performance reasons) only the tree sprites appear.
    The ground doesn't.
    But when I check the scene view it shows that they're there.
    Heres a video of my problem.
    https://imgur.com/a/i2ONINl

    Heres the script for both teleporters:
    Code (CSharp):
    1. using Cinemachine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class teleportation : MonoBehaviour
    7. {
    8.  
    9.     public Transform tp;
    10.     public Transform player;
    11.  
    12.     public GameObject cam1;
    13.     public GameObject cam2;
    14.     public GameObject fadeEffect;
    15.     public Canvas joystick;
    16.     public GameObject tiles;
    17.     public GameObject enableTiles;
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.        
    22.     }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.        
    28.     }
    29.  
    30.  
    31.     public void joystickopen()
    32.     {
    33.         joystick.enabled = true;
    34.         fadeEffect.SetActive(false);
    35.     }
    36.  
    37.     public void tping()
    38.     {
    39.        
    40.         player.transform.position = tp.transform.position;
    41.  
    42.         cam1.GetComponent<CinemachineVirtualCamera>().enabled = false;
    43.         cam2.GetComponent<CinemachineVirtualCamera>().enabled = true;
    44.         tiles.SetActive(false);
    45.         enableTiles.SetActive(true);
    46.     }
    47.  
    48.     private void OnTriggerEnter2D(Collider2D collision)
    49.     {
    50.         if (collision.gameObject.tag == "player")
    51.         {
    52.  
    53.             joystick.enabled = false;
    54.             fadeEffect.SetActive(true);
    55.             Invoke(nameof(tping), 0.5f);
    56.             Invoke(nameof(joystickopen), 0.5f);
    57.  
    58.  
    59.         }
    60.     }
    61. }
    62.  
     
  2. influjensbahr

    influjensbahr

    Joined:
    Aug 31, 2015
    Posts:
    42
    Hi! Hard to tell from the code and video. It appears like the Z position of your camera changes from -10 to something like -960 after reentering the first scene. A camera position like that could very well be the cause for the ground being invisible in game-view only, as this only affects game view and not scene view. Maybe check that?
     
  3. Nomski

    Nomski

    Joined:
    Apr 13, 2024
    Posts:
    8
    Oh yeah that seems to be the problem.
    I just can't figure out why the Z axis is changing when I go back to the first room.
    And I tried to change the camera's Z axis to something like -10 but it didn't let me.
    Could you suggest a fix?
     
    influjensbahr likes this.
  4. Nomski

    Nomski

    Joined:
    Apr 13, 2024
    Posts:
    8
    I found the problem.
    The object where the player was teleporting to had a z value of -680.

    I just changed the Z value to 0 and it fixed the problem.
    Thank you for noticing the skewed z value:p
     
    influjensbahr likes this.