This seems absolutely crazy, and I cant figure it out. I have a gameobject that i instantiate on GetMouseButtonDown. I created it like this :
tempStreetLamp = Instantiate(lampinstance) as GameObject;
Then when GetMouseButtonUp is triggered, I move it to a new gameobject, and destroy the original, like this:
permamentStreetLamp = Instantiate(tempStreetLamp) as GameObject; Destroy(tempStreetLamp);
for testing purposes, I changed the name of permanent street lamp to pStreetLamp, however this object is being destroyed. the tempStreetLamp, which is meant to be destroyed, is not, and instead the permanent street lamp is. What is going on??
okay okay this is really strange. I tried setting tempStreetLamp.SetActive(false) and its turning permanentStreetLamp to false. and So is permanentStreetLamp.SetActive(false). huh???????
Answer by Bren0831
Mar 16 at 09:17 AM
Did you mix up your variables in the Editor?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
99 People are following this question.
using Contains(gameObject) to find and destroy a gameObject from a list
using destroy with an array of GameObjects (C#)
Trouble with destroying an instantiated prefab
C# Object reference not set to an instance of an object right after GameObject.Instantiate