Author Topic: Sprite Alpha  (Read 13802 times)

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Sprite Alpha
« 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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Alpha
« Reply #1 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?

r.pedra

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 20
  • Posts: 131
    • View Profile
Re: Sprite Alpha
« Reply #2 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.

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: Sprite Alpha
« Reply #3 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

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Sprite Alpha
« Reply #4 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.

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: Sprite Alpha
« Reply #5 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

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Sprite Alpha
« Reply #6 on: March 05, 2014, 01:57:18 PM »
instead of setting alpha to 0,1 it's easier to just disable the UISprite component.