c# - Change sprite in Prefab -


I have a range of management of the game's user interface.

  Public class game manager: Mono Behair (ArrayList sprites; // initialize it for zero start () {sprites = new ArrayList (); Sprites.Add (resource load (" Sprites. Sprites. Sprites.Add ("Load" ("donut", typef (Sprite)); Sprites.Add (resource load ("ice cream", typef (sprite)); Sprites. Add (resource load ("letter", typef (sprite)); Sprites.Add (resource load ("paper", typef (sprite)); Sprites.Add (resource load ("pecricope", typef ( Sprite)); Sprites.Add Sprites.Add (source "load" ("sock", typef (sprite)); Sprites.Add (resource load ("tag", typef (sprite) );); Sprites.Add (for resource load ("underwear", typef (sprite)); for (int x = 0; x & lt; 5; x ++) {for (int y = 0; y & Lt; 5; y ++) {GameObject go = Resources.Load ("ItemPrefab") as GameObject; Go.GetComponent & lt; SpriteRenderer & gt; (). Sprite = sprites [Random. Category (0, sprites .Count)] as Sprite; Float Fx = -2 + 1F * x; Flat FY = -2 + 1F * y; Go.transform.position = New Vector 3 (Fx, FI, 0); Illustration (go); }}}}   

I used the code above to instantify a prefab on the screen several times. Prefab has a Sprite Renderer , which is set to the phantom "tag" (only one name) by default.

As you can see above, I get a random phantom set the phantom price of array list and Sprite Renderer . But on the screen, the phantom "tag" remains.

Note:

  • Scripts in ArrayList have been loaded successfully
  • No errors in runtime / compile time

    When you Instantiate you get a new prefab The copy that you are passing is

    Try setting the phantom on the object that comes back by Instantiate and not on the prefab you are loading. {Int x = 0; x & lt; 5; x ++} {for (int y = 0; y & lt; 5; y ++) {GameObject go = Resources.Load ("ItemPrefab") as GameObject; Go = institute (go) as a game object; Go.GetComponent & lt; SpriteRenderer & gt; (). Sprite = sprites [random] Category (0, sprites.Count)] as Sprite; Float fx = -2 + 1f * x; Flat FY = -2 + 1F * y; Go.transform.position = new vector 3 (fx, fi, 0); }}

    Whatever I have done, the situation on the returned object by Instantiate is changing.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -