Author Topic: Enabling Position Tweening (or any other NGUI script) from another function  (Read 4454 times)

Paul1

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 5
    • View Profile
Hi I've recently purchased NGUI and would first like to say thanks for such a great time saving efficient tool 8-)

I'm fairly new to programming and am only familiar with Unity's Javascript, so not sure if this is a NGUI or Unity question

I'm trying to integrate NGUI in to a game I'm making. I've been stuck on this problem for a couple of days now so help would be greatly appreciated

As my character moves around a house I want to hide and reveal different ui buttons and graphics dependant on the room they are in. I'm using the NGUI Tween Position script attached to the button to move the item (I note that enabling this script via the inspector check box gives the desired result) . 

The Problem is I can't find a way to enable this tween or reverse it via a custom function I call when the character exits or enters a room.

Could anyone advise? (with code snippets or an example if possible as I'm quite junior when it comes to programming)

Thanks in advance  ;D



ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
GetComponent<UITween>().PlayForward() or PlayReverse().

Paul1

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 5
    • View Profile
Thank you for the help, I've been trying to test the code snippet in (what I think is) it's simplest form but get unexpected token errors.  This code is in a script on a different game object.

I don't think I understand how UITweener should be accessed?   :)

  1. var mybutton:GameObject;
  2.  
  3. function ManageNGUIEnter() {
  4.  
  5.         Debug.Log("manage NGUI entering room");
  6.  
  7.         mybutton = mybutton.GetComponent<UITweener>().PlayForward();
  8.        
  9. }
  10.  


I thought it maybe the syntax so I changed <UITweener>  to (UITweener)    but this produces the error unknown identifier: 'UITweener'

Any ideas?

Thanks again in advance


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
You are doing it right, but likely not on the correct object. UITweener is the base class for all tweens. Your code will work only if "mybutton" is what has the tween on it.

Paul1

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 5
    • View Profile
Thanks for the help again, I've checked and I did have the correct object assigned in the inspector, "but_food_l" has the TweenPosition script attached to it

I still get the same error      BCE0005: Unknown identifier: 'UITweener'.

I'm still struggling to identify where the problem actually is?

Is it because...
-My syntax is incorrect?
-I'm trying to access a C# script from a JS script?
-It's a compile order problem like mentioned here? http://answers.unity3d.com/questions/510862/bce0018-the-name-tweenposition-does-not-denote-a-v.html

I've tried to implement many solutions but they each seem to have their own dead ends, I'm not really sure where to go from here?



  1. #pragma strict
  2.  
  3. var mybutton:GameObject;
  4.  
  5. function Start () {
  6.  
  7.         mybutton = GameObject.Find("but_food_l");
  8.  
  9. }
  10.  
  11.  
  12. function ManageNGUIEnter() {
  13.  
  14.         Debug.Log("manage NGUI entering room");
  15.  
  16.         mybutton = mybutton.GetComponent(UITweener)().PlayForward();
  17.  
  18. }
  19.  
  20.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
I don't know javascript so I can't be of much help, but unless you followed instructions from FAQ on how to get NGUI to work with javascript, it simply won't work at all.