G
G
GREAT DNG2021-04-29 14:35:21
C++ / C#
GREAT DNG, 2021-04-29 14:35:21

How to compare object prefab and object?

There is a prefab (which is a trigger 'ohm) that is passed to the script via a public variable:

public GameObject RedSphere;

LZiJS.png

An object is created in the script using it:

Instantiate(RedSphere);

The object is spawned, but when compared (in the OnTriggerEnter function , when the body with the attached script touches the object), the condition is not met:

other.gameObject == RedSphere

Why this is happening and how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2021-04-29
@GREAT_DNG

why this happens - because they are different objects.
How to fix - compare in other ways. At runtime, there is no way to understand whether the object was created from the prefab or not

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question