Hello there,
I have read numerous Unity posts and seem to have the issue still after trying all the suggested solutions.
Before I explain my issue, I will give a quick overview of what I am trying to accomplish, in case there is some other solution that makes more sense rather than what I am trying to do.
I want to have a Game Object appear at the beginning of the round in my game at one of seven or eight possible locations. The locations would be predefined Vector3’s (location in the game world) stored into an array and one would be randomly chosen at the beginning of each round. The object would then spawn at one of those locations, and the game object would then disappear until the next round. Essentially it would be a re-usable game object that could either be deleted, or hidden inbetween rounds.
What I have tried so far is the following…
-
Instantiating the game object at the beginning of the game, and trying to hide it using object.active = false until the first round began, then at which I would set object.active = true. I then tried to delete the object using delete(object) and also deleteimmediate(object, true). I found that the deletion of the game object was not viable solution (as far as I am aware and understood) because it seemed that once it was deleted I could not “bring it back”
-
Tried to have the game object in the scene at the beginning of the game, therefore no instantiating it and doing the same idea of object.active =true/false
-
Tried to use object.GetComponent().enabled = false
-
Tried to use object.GetComponent().enabled = false (or something similar)
-
Tried to use object.setActive = false
As far as I am aware there is no parent setting that is causing an issue with this as it is not under anything in the hierarchy. The object that I was working with to make disappear was a primitive Sphere.
Here are code snippets of what I have been trying… These are not all going at once but rather just a list of different things I have tried which relate to items 1-5 above.
//DestroyImmediate(cat, true);
…
public void Despawn()
{
cat.GetComponent().enabled = false;
}
…
public void Spawn()
{
int i = 0;
i = Random.Range(0, spawnPoints.Length);
cat.transform.position = spawnPoints*.position;*
cat.GetComponent().enabled = true;
//Instantiate(cat, catStartPos, Quaternion.identity);
//cat.active = false;
}
…
//Instantiate(cat, catStartPos, Quaternion.identity);
//cat.GetComponent().enabled = true;
…
So if anyone has any suggestions as to what to try or how to do this better/smarter I would be appreciative for any help. I know what I am trying to do is not impossible and I am likely just not seeing it right now. I am new to Unity but not new to game dev.
Thank you!