Quantcast
Channel: UGUI & TextMesh Pro
Viewing all articles
Browse latest Browse all 23263

Pass multiple parameters in button method to instantiate UI prefab

$
0
0
I want to make a method that can instantiate any UI prefab I plug into it so it has multiple uses. I know that the UI buttons can only hold 1 parameter. is there a work around?

Code (CSharp):
  1. public void InstantiateUIElement(GameObject canvas, GameObject UIPrefab, int x, int y){
  2.         Instantiate(UIPrefab, new Vector2(x,y), Quaternion.identity);
  3.         UIPrefab.transform.SetParent(canvas, false);
  4.     }

Viewing all articles
Browse latest Browse all 23263

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>