Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: firestorm on March 25, 2015, 01:13:42 AM

Title: UICenterOnChild.centeredObject example
Post by: firestorm on March 25, 2015, 01:13:42 AM
Hi i was looking for an example on how UICenterOnChild.centeredObject works.

Here is my setup

on my grid I have the UI Center on child script
under that I have 3 labels (easy, medium, hard)

so I now need my button that starts the game to get what label is selected.

If I could just get an example script on how the centeredObject worked would be helpful

Thanks ;D
Title: Re: UICenterOnChild.centeredObject example
Post by: singh029 on March 25, 2015, 05:18:42 AM
Hope this helps:
http://www.tasharen.com/forum/index.php?topic=12796.0

Also take a look at Example 7 - Scroll View (Panel)
Title: Re: UICenterOnChild.centeredObject example
Post by: firestorm on March 25, 2015, 06:36:51 PM
I just wanted to show people how I got mine to work for others in the future

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class selectBackgroundScript : MonoBehaviour {
  5.         public UICenterOnChild backgroundRef; // drag the object that has the centeronchild script attached in my case it was the grid
  6.        
  7.         public void Update()
  8.         {
  9.                 if (backgroundRef.centeredObject.name == "grassBackground")
  10.                         grassBackground ();
  11.                 else if (backgroundRef.centeredObject.name == "picnicBackground")
  12.                         picnicBackground ();
  13.                 else
  14.                         kitchenBackground ();
  15.         }
  16.  
  17.         public void grassBackground()
  18.         {
  19.                 UISprite sprite = GetComponent<UISprite> ();
  20.                 if (sprite.spriteName != "Grass_Background")
  21.                 {
  22.                         sprite.spriteName = "Grass_Background";
  23.                 }
  24.         }
  25.  
  26.         public void picnicBackground()
  27.         {
  28.                 UISprite sprite = GetComponent<UISprite> ();
  29.                 if (sprite.spriteName != "Picnic_Background") {
  30.                         sprite.spriteName = "Picnic_Background";
  31.                 }
  32.         }
  33.  
  34.         public void kitchenBackground()
  35.         {
  36.                 UISprite sprite = GetComponent<UISprite> ();
  37.                 if (sprite.spriteName != "Kitchen_Background")
  38.                 {
  39.                         sprite.spriteName = "Kitchen_Background";
  40.                 }
  41.         }
  42.  
  43. }
  44.