Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - singh029

Pages: [1] 2
1
NGUI 3 Support / Re: prevent click through to bottom ngui widget.
« on: February 22, 2016, 07:27:47 PM »
These links might help:

http://answers.unity3d.com/questions/585108/how-do-you-access-sorting-layers-via-scripting.html

http://forum.unity3d.com/threads/list-of-sorting-layers.210683/

Cheers.

thank you for your help but i just solved it by putting a box collider on the panel so it absorbs the clicks. :)
I apologize, I didn't ask the correct questions.

2
NGUI 3 Support / prevent click through to bottom ngui widget.
« on: February 22, 2016, 02:22:24 AM »
I was wondering if theres a way to get the layer name of the widget that is clicked.

Im using playmaker to call a void method on click of outside area (not panel) to disable a panel. But everytime i click the panel it keeps closing. The click keeps falling through to the widget below it, so it closes. How do i prevent that?

Im setting UI Camera depth on layers but that doesnt seem to help.

Please save mee!

3
NGUI 3 Support / Detect touch outside of panel when panel is open
« on: December 14, 2015, 11:46:07 PM »
is there an ngui way to detect when user touches outside of the panel when the panel is open.

an open panel is visible on the screen. a closed panel slides off of the screen.

I was trying to use this method

http://answers.unity3d.com/questions/947856/how-to-detect-click-outside-ui-panel.html

but ngui panel and rect transform dont play well together.

Currently i just have a box collider that slides in with the panel.
There has to be a better method!

4
NGUI 3 Support / Re: UICenterOnChild.centeredObject example
« 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)

5
NGUI 3 Support / Re: How to skip items on UICenterOnChild
« on: March 25, 2015, 05:13:30 AM »
Thank you so much! i finally got it!
I made copies of all the scripts referenced and then made the following changes.
Only thing i changed is whats in red.

for (int i = 0, imax = trans.childCount, ii = 0; i < imax; ++i)
      {
         Transform t = trans.GetChild(i);
         if (!t.gameObject.activeInHierarchy) continue;
         float sqrDist = Vector3.SqrMagnitude(t.position - pickingPoint);
         
         if (sqrDist < min && t.GetComponent<UISprite>().color != Color.grey)
         {
            min = sqrDist;
            closest = t;
            index = i;
            ignoredIndex = ii;
         }
         ++ii;
      }

Also in UICenterOnClick i changed this as well

if (center.enabled && transform.GetComponent<UISprite>().color != Color.grey)

6
NGUI 3 Support / How to skip items on UICenterOnChild
« on: March 22, 2015, 08:55:47 PM »
Hi, Im trying to figure out a way to skip items in a scrollview if the item is not unlocked.

The UICenterOnChild currently centers on every element when scrolling.
But id like it to skip centering items that arent unlocked and center on the next unlocked item.

When i run the folowing code, it doesnt do anything. Im pretty sure i have to utilize CenterOn(transform). But im unsure how.

  1.  
  2. public static List<bool> ItemLock;
  3.         public static string curItem;
  4.         public List<UISprite> itemList;
  5.         public UICenterOnChild items;
  6.         private int selecteditem;
  7.  
  8. void Update ()
  9.         {
  10.                 Invoke ("ItemSelection", .01F);
  11. }
  12.  
  13. void ItemSelection()
  14.         {
  15.                 switch (items.centeredObject.tag)
  16.                 {
  17.                 case "Apples":
  18.                 {
  19.                         selecteditem= 1;
  20.                         if (ItemLock[1] == true)
  21.                         {
  22.                                 curItem = "Apples";
  23.                         }
  24.                         else{
  25.                                 items.CenterOn(itemList[NextUnlockedItem()].transform);
  26.                         }
  27.                         break;
  28.                 }
  29.                 case "Bananas":
  30.                 {
  31.                         selecteditem= 2;
  32.                         if (ItemLock[2] == true)
  33.                         {
  34.                                 curItem = "Bananas";
  35.                         }
  36.                         else{
  37.                                 items.CenterOn(itemList[NextUnlockedItem()].transform);
  38.                         }
  39.                         break;
  40.                 }
  41.         case "RocketLauncher":
  42.                 {
  43.                         selecteditem= 3;
  44.                         if (ItemLock[3] == true)
  45.                         {
  46.                                 curItem = "Rocket";
  47.                         }
  48.                         else{
  49.                                 items.CenterOn(itemList[NextUnlockedItem()].transform);
  50.                         }
  51.                         break;
  52.                 }
  53.        }
  54. }
  55.  
  56.  
  57.         int NextUnlockedItem()
  58.         {
  59.                 int nextavailable = 0;
  60.                 while(ItemLock[selecteditem] == false)
  61.         {
  62.                         nextavailable = selecteditem;
  63. nextavailable++;
  64.                 }
  65.                 return nextavailable;
  66.         }
  67.  


Please save me!
thank you!

7
NGUI 3 Support / Re: Unity GUI to NGUI conversion help
« on: February 04, 2015, 03:54:56 AM »
So i think i almost got it. Only issue im having now is that the sprite isnt moving.
I just need to instantiate the sprite prefab (progIcon) and set it as the child of the bar sprite and then update the progIcon's position.
How do you get the width of a sprite? bar.width?
The highlighted code is what im unsure of.

void Update ()
   {
      if(LoadData.locatePlayer)
      {
         playerPos = GameObject.FindGameObjectWithTag("Player").transform;
         NGUITools.AddChild(bar.gameObject,progIcon.gameObject);
      }
      // get level distance by subtracting start and end
      float totalDist = endPoint.position.x - startPoint.position.x;
      
      // get player distance from start in X axis only so slopes / height doesn't affect result
      float playerDist = playerPos.position.x - startPoint.position.x;
      
      //get player's progress as a percentage of the whole distance
      float playerProgress = playerDist / totalDist * 100;
      
      //turn the playerProgress percentage back into the scale of barWidth
      barProgress = playerProgress / 100 * bar.width;

      progIcon.transform.Translate(barProgress, 0,0);
   }

8
NGUI 3 Support / Re: Unity GUI to NGUI conversion help
« on: February 03, 2015, 11:20:48 AM »
I understand but if i need multiple thumbs on the slider then id need to go about a custom approach.

9
NGUI 3 Support / Unity GUI to NGUI conversion help
« on: February 03, 2015, 12:34:57 AM »
Hi, I'm not very familiar with Unity GUI and was hoping someone could help me convert the following code.
Basically its a progressbar for a race game. The issue is that the player icon (progIcon) keeps going off the progressbar and off the screen.

This is the original Unity GUI version
http://www.unity3dstudent.com/2011/02/platformer-progress-bar/

And this is my failed NGUI version. The Unity GUI code is commented out.
  1. public class RaceProgressBar2 : MonoBehaviour {
  2.  
  3.         // set GUI bar width and height in the Inspector
  4. //      private float barWidth = 350;
  5. //      private float barHeight = 25;
  6.         public UISprite bar;
  7.  
  8.         // drag a texture as the icon to move on the progress bar
  9.         public UISprite progIcon;
  10.        
  11.         // where to set the GUI element to
  12.         private float barProgress;
  13.        
  14.         // empty objects represent the start and end of a level
  15.         public Transform startPoint;
  16.         public Transform endPoint;
  17.        
  18.         // current Player position
  19.         private Transform playerPos;
  20.  
  21.         void Update ()
  22.         {
  23.                 if (playerPos == null)
  24.                 {
  25.                         playerPos = GameObject.FindGameObjectWithTag("Player").transform;
  26.                 }
  27.                 // get level distance by subtracting start and end
  28.                 float totalDist = endPoint.position.x - startPoint.position.x;
  29.                
  30.                 // get player distance from start in X axis only so slopes / height doesn't affect result
  31.                 float playerDist = playerPos.position.x - startPoint.position.x;
  32.                
  33.                 //get player's progress as a percentage of the whole distance
  34.                 float playerProgress = playerDist / totalDist * 100;
  35.                
  36.                 //turn the playerProgress percentage back into the scale of barWidth
  37.                 barProgress = playerProgress / 100 * (1-bar.gameObject.transform.position.x); // playerProgress / 100 * barWidth;
  38.  
  39.                 progIcon.transform.position = new Vector3 (barProgress, 0,0);
  40.         }
  41.        
  42.         void OnGUI ()
  43.         {
  44.                 // create a GUI group the width of the bar and twice its height
  45.                 // in order to leave room for 'Start' and 'End' text under the bar
  46. //              GUI.BeginGroup (new Rect (10, 10, barWidth, barHeight*2));
  47.                
  48.                 //draw a box as the backing for the progress bar, blank text inside
  49. //              GUI.Box( new Rect(0,0,barWidth,barHeight),"");
  50.                
  51.                 // create a label to draw the progress icon texture, use barProgress var
  52.                 // to set its X position, 0 as the Y position and width and height of the texture used
  53. //              GUI.Label ( new Rect(barProgress, 0, progIcon.width, progIcon.height),progIcon);
  54.                
  55.                 // add start and end labels
  56. //              GUI.Label( new Rect(progIcon.width/2, 25, 50, barHeight),"Start");
  57. //              GUI.Label( new Rect(barWidth-30, 25, 100, barHeight),"End");
  58.                
  59. //              GUI.EndGroup();
  60.         }
  61.  
  62. }


Thanks for helping!  :)


10
NGUI 3 Support / Chain Pingpong Tween Position
« on: June 02, 2014, 05:24:03 AM »
Could you suggest a way to pingpong 2 sprites using OnFinished or when the sprite equals a certain position.
I want to have the second sprite start after the first one gets back to its initial (from) position.
The logic is wrong. Since Pingpong is endless, how do i check if it reached its initial position again so i can start the second sprite?

  1.        
  2. void Update()
  3. {
  4.      if (leftPosTween.to.sqrMagnitude >  new Vector3(0,70,0).sqrMagnitude)
  5.      {
  6.             rightPosTween.enabled = true; // set to false in Start()
  7.             rightPosTween.Play();
  8.      }
  9. }
  10.  
  11.  

11
NGUI 3 Support / Re: How do I block click events on a button
« on: April 30, 2014, 11:42:46 AM »
So can i do something like..

  1. if(UICamera.GetMouse(0))
  2. {
  3. }

If so, is there a static variable to get mouse position?

Or do i need to use the public attribute
  1. Vector2 pos

And im assuming i would need to create a UICamera variable and throw the camera in there, correct?

And do something like..

  1. Vector2 position = uicam.pos;

12
NGUI 3 Support / Re: How do i get Scrollview center on child element
« on: April 29, 2014, 10:05:16 PM »
sweet! thanks a lot! it works!

13
NGUI 3 Support / How do I block click events on a button
« on: April 29, 2014, 01:15:11 AM »
The player keeps jumping when i click on the pause button.

Is there a way to display click events on top of a button so only the button event is fired, not the click event?

For screen clicks im using

  1. Input.GetMouseButton(0)
and
  1. Input.mousePosition

14
NGUI 3 Support / How do i get Scrollview center on child element
« on: April 29, 2014, 01:08:15 AM »
Is there any way to get the element that is centered in a scrollview with center on child?

15
NGUI 3 Support / Panel drag snap
« on: April 17, 2014, 11:34:54 AM »
I want to create a panel drag feature where i can horizontally drag a sprite (thats on the edge of the screen) with a panel child and it will snap to the center of the screen.

I got everything working except the snapping part.
I was trying to make use of the UICenterOnChild script. but the script wouldnt turn on when i attached it to the panel and ran the project.
Do i need to attach it to the panel's parent panel (MainMenuPanel)?

Pages: [1] 2