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 - HypoXic5665

Pages: [1]
1
NGUI 3 Support / Re: Setting UICamera.fallThrough
« on: January 09, 2013, 09:24:27 PM »
I know in JavaScript it would look like:

  1. var cam: UICamera;
  2.  
  3. function Start(){
  4.         cam.fallThrough = this.gameObject;
  5. }
Where you would drag your main camera (with a UICamera component) onto the cam variable in the inspector. Or get it dynamically of course.

I am not familiar with C# so I would'nt be able to say for sure. I am sure someone here knows though.

EDIT:
Played around with it abit in C#.

"UICamera.fallThrough = this.gameObject;"

On a script on your 'ListenerGameObject'  will do, as ArenMook stated above.

2
NGUI 3 Support / Re: Issue setting variable with OnPress()
« on: November 18, 2012, 02:18:41 PM »
Thanks Nicki! I definitely was using the OnPress() entirely wrong and being redundant. I'm not sure if my code is as efficient as possible now but i'm definitely going the right way now.

Thanks again.

3
NGUI 3 Support / Issue setting variable with OnPress()
« on: November 18, 2012, 01:31:53 AM »
Hi, I am having an issue with an OnPress() for my mobile game. I am sure it is just from my lack of understanding of how the touch functions work with NGUI. If anyone could help clarify or point out what my mistake might be it would be appreciated.

So pretty much I have two scripts, Button.js and ControlCenter.js. When the NGUI button is pressed I am setting the boolean <nguiTouched = true> (via Button.js)  which lives in the ControlCenter.js. This is working how I would expect except for when the button is released the part of the ControlCenter Update function, marked with **, is getting processed and saving the location of the touch release.

The block of code marked should not be getting read since it is inside of the (!nguiTouched) conditional unless I am not understanding how the OnPress() function is called. Am I not using this function properly or is there another function I should be using here?

Thanks in advance,

Button.js
  1. var controlCenter: ControlCenter;
  2.  
  3. private var pressed: boolean = false; //is this button bieng pressed?
  4.  
  5. function OnPress()
  6. {
  7.         if(!pressed)
  8.         {
  9.                 pressed = true;
  10.                 controlCenter.nguiTouched = true;
  11.         }
  12.         else
  13.         {
  14.                 pressed = false;
  15.                 controlCenter.nguiTouched = false;
  16.         }
  17. }

ControlCenter.js
  1.  
  2. var nguiTouched: boolean = false;
  3.  
  4. function Update ()
  5. {
  6.         if(!nguiTouched)
  7.         {
  8.                 if(Input.touchCount > 0) //if the user presses the screen...
  9.                 {
  10.                         var touch: Touch = Input.touches[0];
  11.                         touchTime += Time.deltaTime; //to avoid accidental presses
  12.                                                                        
  13.                         **if(needInitialTouchLoc) //get the loc of the initial touch position **
  14.                         **{                                                                                                  **
  15.                         **      initialTouchLoc = Input.GetTouch(0).position;                         **
  16.                         **      needInitialTouchLoc = false;                                                    **
  17.                         **      print("initialTouchLoc: " + initialTouchLoc);                              **
  18.                         **}                                                                                                  **
  19.  
  20.            if(other parameters)
  21.           {
  22.                      do other stuff....
  23.            }
  24.      }
  25.   }
  26. }
  27.  
  28.  
  29.  

4
NGUI 3 Support / Re: NGUI Buttons interacting with a NGUI slider value
« on: October 14, 2012, 05:53:47 PM »
Description from Unity Scripting Reference-
"OnMouseUpAsButton() is only called when the mouse is released over the same GUIElement or Collider as it was pressed."

It appears to act the same as OnClick(). The problem still occurs with OnClick() or OnPress() as well. Is this method even the correct or most direct way to go about changing the slider value via a separate button in NGUI?

Thanks,

5
NGUI 3 Support / NGUI Buttons interacting with a NGUI slider value
« on: October 14, 2012, 04:08:02 PM »
Hello, I currently have a slider that can be adjusted via the slider itself or one of two NGUI buttons (up and down). When the "up" or "down" button is pressed the value increases or decreases as expected. However, pressing the "up" folowed by the "down" button causes the value to increase by one, then continued presses on the "down" button act as expected.

Example:
Power = 300
Press up button: Power = 301
Press up button: Power = 302
Press down button: Power = 303 << This is the problem
Press down button: Power = 302
Press down button: Power = 301

Here is the code that is on the NGUI Slider:
  1. static var power: int; //power that will be passed to the egg when shot
  2. var slider: UISlider; //will become the <Power_Slider>s <UISlider> component
  3.  
  4. //values for the slider
  5. var minPower: int = 200; //the min power that the slider will be able to input
  6. var maxPower: int = 500; //the max power that the slider will be able to input
  7.  
  8. function Start()
  9. {
  10.         slider = gameObject.GetComponent(UISlider); //get the <UISlider> component of the power slider
  11. }
  12.  
  13. function Update ()
  14. {
  15.         power = Mathf.Lerp(minPower,maxPower,slider.sliderValue); //set the sliders min and max values
  16. }

And here is the code on the NGUI Buttons:
  1. var powerSlider: UISlider; //to get and adjust the slider value
  2.  
  3. private var sliderInc: float = 0.003335;
  4.  
  5. function OnMouseUpAsButton()
  6. {
  7.         if(gameObject.name == "Power_Button_Up") //if the <Up_Button> is pressed then increase the slider value...
  8.         {
  9.                 powerSlider.sliderValue = powerSlider.sliderValue + sliderInc;
  10.                 print(gameObject.name + "s power is: " + GameObject.Find("Power_Slider").GetComponent(PowerSlider).power);
  11.         }else //else the down button was pressed so decrease the slider value...
  12.         {
  13.                 powerSlider.sliderValue = powerSlider.sliderValue - sliderInc;
  14.                 print(gameObject.name + "s power is: "  + GameObject.Find("Power_Slider").GetComponent(PowerSlider).power);
  15.         }      
  16. }

Any help will be appreciated to lead me in the right direction to fix this issue.

Thanks in advance,

6
NGUI 3 Support / Re: Changing slider values
« on: September 30, 2012, 10:49:45 PM »
Thanks! This works now. Am new to NGUI and am still figuring it all out.

7
NGUI 3 Support / Re: Changing slider values
« on: September 30, 2012, 08:40:07 PM »
Where can I use this? I get a compilation error where ever I try to put it. "Unknown identifier: 'slider'" How do I need to call or define 'slider' in the script to have this work?

8
NGUI 3 Support / Changing slider values
« on: September 30, 2012, 05:45:28 PM »
Hello, I am trying to make a slider for a power bar with different values than the default. Similar to this post:

http://www.tasharen.com/forum/index.php?topic=425.msg2030#msg2030

It says in there to use this code:

yourValue = Mathf.Lerp(start, end, slider.sliderValue);

Where do I need to put this code and how do I call this value after it has been set/changed.

Thanks for the help,

Pages: [1]