intenemyIndex=Random.Range(0,m_enemyList.Length);
varenemyObject=Instantiate(m_enemyList[enemyIndex], new Vector3(0,3,0), transform.rotation) as GameObject;
varbackground2 = GameObject.FindGameObjectWithTag("background");
enemyObject.transform.SetParent(background2.transform, false);
It's randomly generated with this kind of course.Create something called destroy.cs and
We add conditions to destroy (generated prefab) to destroy HP when it reaches zero.
At that time, since it is a different cs that manages HP (enemy.cs),
enemy.cs is located at destroy.cs.
I'd like to attach it, but I can't select the scene, so I can't attach it
The instance (prefab) you want to generate is not on the hierarchy,
Is it because it is on the project?
I'm sorry if I couldn't read your question.
From the title and questionnaire, there seems to be confusion between the use of the terms "instance" and "pre-fabricated."
Do you want to add components (enemy.cs or destroy.cs in the questionnaire) to prefabricated (prefabricated assets in Project View)?
Or is it for instance generated from prefabricated (e.g., enemyObject in question statement)?
To add a component to a prefabricated object, click the prefabricated object in Project View, and then add the component on the displayed inspector.
Otherwise, if it's "how to attach components to an instance" according to the title,
enemyObject.AddComponent<(name of component written on destroy.cs or enemy.cs)>()
You can add components as shown in .
In the questionnaire,
The instance (prefab) you want to generate is not on the hierarchy,
Is it because it is on the project?
So I thought it was probably the former (how to add components to a prefabricated asset), but I also wrote the latter (how to add components to an instance) just in case.
2015-11-27 16:08 Add
By any chance, are you trying to correlate Enemy in the inspector of the destory component by dragging and dropping enemy.cs in Project View?
Enemy can drop either an instance (GameObject) on a hierarchy or a prefabricated one in the Project View.Therefore, I think it can be associated by preparing GameObject or prefabricated with enemy components in advance and then dragging and dropping Enemy.
If the association is successful, the Enemy assignment display should change to "(GameObject Name or Prefabricated Name) (enemy).This indication means "referencing an enemy component added to a GameObject or prefabricated".
© 2024 OneMinuteCode. All rights reserved.