Author Topic: Cant change sprite via code in NGUI free  (Read 3141 times)

piearesquared0

  • Guest
Cant change sprite via code in NGUI free
« on: October 13, 2013, 02:50:58 PM »
 Ive had alot of trouble with this and im not sure if it because of my lack of experience with NGUI or lack of skill in unity, i try everything i can think of to change the sprite via code (tried both cs and js) and i get an error everytime

this
  1. void Update ()
  2.         {
  3.                 UISlicedSprite spr;
  4.                 spr=this.GetComponent(UISlicedSprite);
  5.                 spr.spriteName=items.items[id].name;
  6.         }
  7.  

this
  1. void Update ()
  2.         {
  3.                 UISlicedSprite spr;
  4.                 spr=GetComponent(UISlicedSprite);
  5.                 spr.spriteName=items.items[id].name;
  6.         }
  7.  

this
  1. void Update ()
  2.         {
  3.                 UISlicedSprite spr;
  4.                 spr=this.gameObject.GetComponent(UISlicedSprite);
  5.                 spr.spriteName=items.items[id].name;
  6.         }
  7.  

and every time i get loads of errors dealing with type conversions

Assets/scripts/engine/system/invItemBox.cs(17,39): error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
Assets/scripts/engine/system/invItemBox.cs(17,26): error CS1502: The best overloaded method match for `UnityEngine.Component.GetComponent(System.Type)' has some invalid arguments
Assets/scripts/engine/system/invItemBox.cs(17,26): error CS1503: Argument `#1' cannot convert `object' expression to type `System.Type'


ive even tried replacing the () with <> and that just adds more errors, please help!

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Cant change sprite via code in NGUI free
« Reply #1 on: October 13, 2013, 03:57:47 PM »
Getcomponent is written like this

  1. spr = GetComponent<UISlicedSprite>();
« Last Edit: October 13, 2013, 05:08:18 PM by Nicki »