Author Topic: Transform parent  (Read 4497 times)

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Transform parent
« on: February 26, 2014, 11:34:08 AM »
Hi,
I'm trying to instantiate a sprite startup that represents user. In this mode user can choose which team to play by clicking on the logo of one of the two teams.
My problem is that when I clicking on the logo and it starts ClickTeam1(), my gameObject moves correcty but sprite aren't vsible (I insert a image to help you to understand me)
It works good if I remove comment on the line of code in order to generate other prefab, but I only want to move the existing one.




  1.         public GameObject user_selection, grid_viewers, grid_team1;
  2.         GameObject user;
  3.  
  4.         void inizialize()
  5.         {
  6.                 user = (GameObject)Instantiate(user_selection, new Vector3(0,0,0), Quaternion.identity);
  7.                 user.transform.parent = grid_viewers.transform;
  8.                 user.transform.localScale = Vector3.one;
  9.                 grid_viewers.GetComponent< UIGrid >().Reposition();
  10.         }
  11.  
  12.         public void ClickTeam1()
  13.         {
  14.                 //user = (GameObject)Instantiate(user_selection, new Vector3(0,0,0), Quaternion.identity);
  15.  
  16.                 user.transform.parent = grid_team1.transform;
  17.                 user.transform.localScale = Vector3.one;
  18.  
  19.                 grid_team1.GetComponent< UIGrid >().Reposition();
  20.                 grid_viewers.GetComponent< UIGrid >().Reposition();
  21.         }

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: Transform parent
« Reply #1 on: February 26, 2014, 12:29:15 PM »
I changed iniziale() in this mode:

  1. void inizialize()
  2.         {
  3.                 user = NGUITools.AddChild (grid_viewers, user_selection);
  4.                 grid_viewers.GetComponent< UIGrid >().Reposition();
  5.         }

I see that it's better mode to instanziate prefab, but I still have the problem on ClickTeam1()

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Transform parent
« Reply #2 on: February 26, 2014, 02:33:42 PM »
Whenever you change the parent like that, you need to notify the widgets, informing them that the parent has changed. UIWidgets have a function for that: MarkParentAsChanged().

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: Transform parent
« Reply #3 on: February 26, 2014, 03:38:11 PM »
Perfect with NGUITools.MarkParentAsChanged (user); work nice :D
Thank you :D