- Home /
Change UI GUI Image Sprite at runtime .. Unity 5 .. js
Hi,
I'm trying to swap a image sprite of a UI GUI but it's not swapping, what is wrong with my code ? .. I'm getting no errors.
Thanks.
  #pragma strict
  
  import UnityEngine.UI;
  
 private var GUIweaponSprite : Sprite;
      
 function Start ()
 {
       GUIweaponSprite = GameObject.Find("Info Disk Weapon").GetComponent.<Image>().sprite;
 }
      
 function OnGUI ()
 {
        GUIweaponSprite = _weapons[2];
  }
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by prof · Aug 25, 2015 at 06:16 PM
  private var GUIweaponImage : Image;
       
  function Start ()
  {
        GUIweaponImage = GameObject.Find("Info Disk Weapon").GetComponent.<Image>();
  }
       
  function OnGUI ()
  {
         GUIweaponImage.sprite = _weapons[2];
   }
Your answer
 
 
             Follow this Question
Related Questions
Is there a way to see if a sprite is sliced in code? 1 Answer
Order Issues - How to order UI correctly - Canvas, Sprite, Panel with Background (Image) 0 Answers
Check if UI element is fully inside another UI element 1 Answer
Interface relative scaling 0 Answers
Pixels Per Unit good practice query 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                