I need help destroying a clone on function.
I have 4 items(prefabs), that should stay permanently, but when you combine 2 of them, they create(instantiate clone) a one time use item. I want to create a script , that when it gets used (a function from main script), it should be deleted. I have tried many things in the last 2 hours and nothing worked. The main solution I am trying is putting a script on the prefab and then referencing it through the main script, so when the use function happens, the deletion function on the prefab happens, but it appears to only work on one of the prefabs I reference, not any of the other prefabs and the clones. Could anyone please help? I need it done today.
Answer by tormentoarmagedoom · Oct 06, 2019 at 11:55 AM
Hello there.
There are mltuiple ways to get that. As you say , you can have finctions in each prefab, or you can also have a main script that controls everything.
Withous look your scripts its hard to know what is happening.
What i recommend, if you have only 4 items, is to have a main script where all is referenced and controlled. But haviing a script in each objects is 100% functional so is also a good solution.
Please show us your scripts so we can say what is happening.
PS: A "clone", is a instantiated object in the scene. Once a instance of a prefab is on the scene, it is a GameObject like any other, does not matter if it came form a prefab, or it was instantiated, or was there from the begining. All scene GameObjects are the same. So you only need to have the correctly asigned to a GameObject variable in some of your scriipts, and use the Destroy() function. If its not working, is because you dont have them coprrectly asigned top the variable.
Debug your code to know the value of each variable every moment while running, to detect what is null or what variable is not what is is suposed to be. And a tip: The error is always yours, never is a Unity fault :D
Good luck!