- Home /
How to tell the number of instantiated object
Hey guys, In my project I instantiate a GameObject everytime I hit right mouse button. At the same moment I am creating an listelement in my flexible list. I want to control a specific GameObject with the corresponding listelement e.g delete the second one called "Schweißnaht 2". The GameObject (sphere) and the listelement are both prefabs.
How can i connect them so I can control the GameObjects within the corresponding listelement?
Kind regards, Stefan
//creating a listelement
display = (GameObject)Instantiate(ItemDisplayPrefab);
//target in hierarchy
display.transform.SetParent(targetTransform, false);
//Change name
display.name = "Schweißnahtelement " + SchweißnahtZahl ;
Debug.Log(Nahtzahl);
//Creating an element
void CreateFirstElement(Vector3 mousePosition)
{
//create object
newObject = Instantiate(Kugel, mousePosition, transform.rotation);
//name object and increase counter
newObject.name = "Punkt " + Counter;
Counter++;
//Rotation des Objektes auslesen
mousrot = newObject.transform.localEulerAngles;
// Which type is it
Typ = ButtonChangeSphereType.Type;
//add coordinates to list
Trajektory.Add(new Trajektory(mousposneu.x, mousposneu.y, mousposneu.z, mousrot.x, mousrot.y, mousrot.z, Typ));
//target in hierarchy
newObject.transform.parent = newContainer.transform;
}
Answer by Goat-Boy · Jul 23, 2019 at 12:33 PM
It sounds like you want to create a struct that holds both your trejectory information and a refrence to the corresponding gameObject. You then have a list of those structs that you can add to whenever you Instanciate a new ball.
Answer by solutionlab · Jul 24, 2019 at 06:00 AM
Hey Goat-Boy, thanks for the answer :-) I added two lines of code:
//Create Object for listelement
display = (GameObject)Instantiate(ItemDisplayPrefab);
//target
display.transform.SetParent(targetTransform, false);
**//giving attribute Pos the acutal weld-number
var thescript = display.GetComponent<ButtonActionManager>();
thescript.Pos = SchweißnahtZahl;**
//change Name
display.name = "Schweißnahtelement " + SchweißnahtZahl ;
Your answer
Follow this Question
Related Questions
How to make camera position relative to a specific target. 1 Answer
Troubles instatiating a gameobject with rotation 0 Answers
Trying to load a prefab but getting null error 4 Answers
Player controlled prefab not moving in new Scene 1 Answer
How to Snap Hallway Tile Prefabs Together Seamlessly so that Don't Overlap? 0 Answers