HI
I’ve got a sprite prefab that works totally normal if you put it into the scene manually but if I instantiate it, it is not visible in the game view, only in the scene view.
images:
HI
I’ve got a sprite prefab that works totally normal if you put it into the scene manually but if I instantiate it, it is not visible in the game view, only in the scene view.
images:
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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
public float bulletForce = 20;
/*void Update()
{
if (Input.GetButtonDown("Fire1"))
{
//Debug.Log("test");
Shoot();
}
}*/
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
}
private void Update()
{
if(Input.GetButtonDown("FireW") || Input.GetButtonDown("FireA") || Input.GetButtonDown("FireS") || Input.GetButtonDown("FireD"))
{
//Shoot();
StartCoroutine(WaitShoot());
}
}
IEnumerator WaitShoot()
{
yield return new WaitForSeconds(0.01f);
Shoot();
}
}
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.
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: Unity - Manual: 2D Sorting
I have a blog post about sorting tiles on the Tilemap but the method shown there should work for your issue as well How to sort sprites in unity using Y position — Sunny Valley Studio
I hope it helps!