Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Why are my sprites rendering in Scene view but not in game view?!?!

Discussion in '2D' started by Nlk29, Mar 5, 2022.

  1. Nlk29

    Nlk29

    Joined:
    Jan 25, 2022
    Posts:
    39

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,521
    I don't know the answer to your question but I did approve your post as it was flagged for moderation because of your use of swearing in the title which I also removed. Please refrain from posting language like that.
     
    SunnyValleyStudio likes this.
  3. Nlk29

    Nlk29

    Joined:
    Jan 25, 2022
    Posts:
    39
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Shooting : MonoBehaviour
    6. {
    7.     public Transform firePoint;
    8.     public GameObject bulletPrefab;
    9.  
    10.     public float bulletForce = 20;
    11.    
    12.     /*void Update()
    13.     {
    14.         if (Input.GetButtonDown("Fire1"))
    15.         {
    16.             //Debug.Log("test");
    17.             Shoot();
    18.         }
    19.     }*/
    20.  
    21.     void Shoot()
    22.     {
    23.         GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
    24.         Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
    25.         rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
    26.     }
    27.  
    28.     private void Update()
    29.     {
    30.          if(Input.GetButtonDown("FireW") || Input.GetButtonDown("FireA") || Input.GetButtonDown("FireS") || Input.GetButtonDown("FireD"))
    31.         {
    32.             //Shoot();
    33.             StartCoroutine(WaitShoot());
    34.         }
    35.  
    36.     }
    37.  
    38.     IEnumerator WaitShoot()
    39.     {
    40.         yield return new WaitForSeconds(0.01f);
    41.         Shoot();
    42.  
    43.     }
    44. }
    45.  
     
  4. SunnyValleyStudio

    SunnyValleyStudio

    Joined:
    Mar 24, 2017
    Posts:
    67
    Hey!

    This seems like a sorting order issue. I can see that your Sprite Renderer has the sorting layer set as "default" and the Order in Layer is 0. If you have your Tiles or any other sprite in the same spot on the same default sorting layer and with the same order in layer there is no telling which of those will be rendered first so chances are that this sprite is there but under the white sprite.

    upload_2022-3-18_11-16-5.png

    upload_2022-3-18_11-17-58.png

    The solution would be to create a new sorting layer ex "Bullet" and to place your bullet element on this layer so that it always is rendered on top of the environment sprites.

    You can read more about it in the documentation: https://docs.unity3d.com/Manual/2DSorting.html
    I have a blog post about sorting tiles on the Tilemap but the method shown there should work for your issue as well https://www.sunnyvalleystudio.com/blog/how-to-sort-sprites-in-unity

    I hope it helps!