Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Noi14 on March 04, 2014, 11:52:08 AM

Title: Sprite Alpha
Post by: Noi14 on March 04, 2014, 11:52:08 AM
Hi,
I can't change alpha of a sprite when I instanziate a object.

  1. GameObject user = NGUITools.AddChild (list, user_selection);
  2. GameObject removeUser = user.transform.Find ("RemoveUser").gameObject;
  3.  
  4.  
  5. if (TNManager.isHosting)
  6. {
  7. Debug.Log("Is host");
  8. removeUser.GetComponent< BoxCollider > ().enabled = true; // Work
  9. removeUser.GetComponent< UISprite > ().alpha = 1; // Doesn't work
  10. }
  11.  

Collider is correctly activated but alpha of sprite doesn't have variations. Why?
Title: Re: Sprite Alpha
Post by: ArenMook on March 05, 2014, 08:10:24 AM
"doesn't have variations"?

If you have a button script on that "removeUser" object, then it will likely overwrite your sprite color when it starts up. Also, why set alpha to 1? Shouldn't it already be 1?
Title: Re: Sprite Alpha
Post by: r.pedra on March 05, 2014, 08:26:33 AM
I think his button is disable by default and he is "activating" it when the user is the host. So I think the button have an alpha of 0 at the start.
Title: Re: Sprite Alpha
Post by: Noi14 on March 05, 2014, 08:43:27 AM
I've setted prefab with alpha at 0, after I have used tned and if client is Host, alpha will set 1 and will be activated collider
Title: Re: Sprite Alpha
Post by: ArenMook on March 05, 2014, 09:04:33 AM
Make sure you have the latest NGUI, there was an issue with going form alpha of 0 in some cases in the past.

I'd also advise leaving the prefab in "enabled" state by default, and disabling the collider / hiding the sprite on instantiation instead.
Title: Re: Sprite Alpha
Post by: Noi14 on March 05, 2014, 09:36:10 AM
I'm using the latest version, but if I enter the code in the update at "press a button" instead of "creation" It works:
  1. void Update () {
  2.                 if(Input.GetKeyDown(KeyCode.L))
  3.                 {
  4. ...code...
  5.                         removeUser.GetComponent< BoxCollider >().enabled = false;
  6.                         removeUser.GetComponent< UISprite >().alpha = 0;
  7.                 }
  8.         }
  9.  
I also try to reverse the functioning, that is disable the buttons putting it enabled by default, but have the same problem
Title: Re: Sprite Alpha
Post by: Nicki on March 05, 2014, 01:57:18 PM
instead of setting alpha to 0,1 it's easier to just disable the UISprite component.