Advertisement
srogee

Assign same value to multiple instances of the same prefab

Mar 4th, 2014
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void OnGUI()
  2. {
  3.         GameObject [] pipes = GameObject.FindGameObjectsWithTag("Holder"); //get all holder gameobjects
  4.    
  5.     foreach(GameObject pipe in pipes) //loop through all holder gameobjects
  6.     {
  7.         SetPipe setPipeScript = pipe.GetComponent<SetPipe>();
  8.             selGridInt = GUI.SelectionGrid(new Rect(50, 70, 100, 500), selGridInt, pipeShape, 1);
  9.         setPipeScript.pipeSelect = selGridInt;
  10.     }
  11. }
  12.  
  13. public class SetPipe : MonoBehaviour {
  14.     public Transform [] pipe; //put this into an array so it's easier to get stuff from it. just set the size to 7 in the Inspector and fill it with your pipe objects.
  15.     public int pipeSelect;
  16.  
  17.         void OnMouseOver()
  18.         {
  19.             if (Input.GetMouseButtonDown(0))
  20.             {
  21.             Debug.Log(pipe[pipeSelect].name);      
  22.             Instantiate(pipe[pipeSelect], gameObject.transform.position, Quaternion.Euler(0, 0, -90));
  23.                         Destroy(gameObject);
  24.         }
  25.     }
  26. }
Advertisement
RAW Paste Data Copied
Advertisement