Home > other >  How to modify prefab instantiate the parameters of the object
How to modify prefab instantiate the parameters of the object

Time:09-27

How to modify prefab instantiation out the parameters of the object
GameObject. GetComponent<> () object
Can only modify the parameters of the prefab inside, I want to change the clone body parameter values rather than do not change the parameter values of prefab,
How to solve

CodePudding user response:

You initialize the on objects in the pool is a pool & lt; The key, GameObject> Each object has a key or id
According to the key for GB set parameters

CodePudding user response:

 
Var SCR=Instantiate (prefab);
SCR. The transform. The parent=p.t ransform;
SCR. The transform. LocalPosition=Vector3. Zero;
SCR. The transform. LocalScale=Vector3. One;
Var starts=SCR. BtnFish. GameObject. GetOrAddComponentStarts. Size=SCR. RectTrans. SizeDelta;
Starts. Offset=SCR. RectTrans. SizeDelta/2 - SCR. RectTrans. Pivot *. SCR rectTrans. SizeDelta;
Starts. The gameObject. Layer=ConstVar. LayerButton;

CodePudding user response:

Bottom:
Public class Object
{
,,,
Public static Object Instantiate (Object the original);
,,,
}

Instantiate this method has a return value, that you generated objects,
GameObject obj=Instantiate (prefab);

You have to do is modify the obj,
  • Related