c# - Storing custom data on a prefab instance -


i have script generates star planets.

each planet have information associated it, instance "type" (lava, rocky etc).

i have trigger set when mouse on planet working:

ray = camera.main.screenpointtoray(input.mouseposition);     if(physics.raycast(ray, out hit))     {         print (hit.collider.name);     } 

i instantiating planets with:

gameobject planetclone = instantiate (planet, pos, quaternion.identity) gameobject; 

how attach string variable "type" instanced prefab?

you can attach script prefab required parameters , method pass them example

// scripta  string type; public void settype(string _type){     type = _type; } 

attach scripta prefab, after instantiating prefab, can use

scripta scripta = (scripta) planetclone.getcomponent<scripta>(); scripta.settype("data want pass comes here"); 

this attached script belonging instantiated gameobject , properties associated it! may refer unity documentation more info


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -