U
U
Uncle Bogdan2021-02-28 10:51:00
C++ / C#
Uncle Bogdan, 2021-02-28 10:51:00

When an object spawns, it is not visible in the game, but it is on the stage. What's the catch?

When I just drag an object onto the stage, everything is fine, when I try using Instantiate, it is not visible in the game (the object is on layer 100, other objects are -1 - 5). What is the problem?
The code:

private void OnTriggerExit2D(Collider2D collision)
    {
        if(collision.CompareTag("Road"))
        {
            OldRoad = collision.gameObject;
            GameObject road = Instantiate(RoadPrefab, collision.transform.parent.position + RoadOffset, Quaternion.identity);
            CarOffset.x = Random.Range(-2f, 2f);
            CarOffset.y = Random.Range(-2f, 2f);
            Instantiate(CarPrefab, road.transform.Find("GameObject").position + CarOffset, Quaternion.Euler(0,0,180));
            Invoke("DeleteRoad", 3f);
        }

    }


Screenshots:
603b4b45c0d70062101113.png
603b4b345eb4e935242738.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question