Author Topic: Using TweenPosition to move gameobject  (Read 14306 times)

wesm

  • Guest
Using TweenPosition to move gameobject
« on: April 26, 2012, 02:20:06 PM »
Hi,

I am using NGUI for a project. I would also like to use some of the tween animations scripts for game objects other than NGUI items. Is this possible? I have a game object that responds to a custom C# event. When the event occurs, I want the object to move. I placed the TweenPosition script on my object. My object also has a script which is listening for my custom event.

I have tried to start the tween animation as follows.

  1. void HandleSwipeDetectorOnSwipe (SwipeDetector.SwipeDirection swipe)
  2.         {
  3.                
  4.                 TweenPosition.Begin(gameObject, 2f, new Vector3(0,500,0));
  5.         }

However, this doesn't trigger the animation. If I simply place values in the "To" field of the TweenPosition script in the Unity Editor, the game object will move. Is it possible to use TweenPosition to animate other objects in my scene beyond NGUI items?

Thanks

Wes

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using TweenPosition to move gameobject
« Reply #1 on: April 26, 2012, 03:37:30 PM »
Yup, Tweens work on game objects, not widgets. Even tween color script isn't limited to widgets -- it works with renderers and lights as well. I don't see a reason why the TweenPosition.Begin wouldn't work. Is the code being called? Do you see a TweenPosition script added in inspector?

dlewis

  • Guest
Re: Using TweenPosition to move gameobject
« Reply #2 on: April 26, 2012, 07:00:03 PM »
Slightly off topic but I'm investigating TweenPosition now and a suggestion I have would be to include an option to tween from 'current position' to 'defined location' (I'm going to be adding it myself as I need it).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using TweenPosition to move gameobject
« Reply #3 on: April 26, 2012, 07:07:17 PM »
Thats how it works if you use TweenPosition.Begin.

dlewis

  • Guest
Re: Using TweenPosition to move gameobject
« Reply #4 on: April 26, 2012, 07:18:31 PM »
Thats how it works if you use TweenPosition.Begin.

If that's the case then what's the point of the from variable?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Using TweenPosition to move gameobject
« Reply #5 on: April 26, 2012, 07:19:10 PM »
Allows you to set it up in the inspector instead of using code.

wesm

  • Guest
Re: Using TweenPosition to move gameobject
« Reply #6 on: April 27, 2012, 02:24:06 PM »
It's working now. I'm not sure what the issue was before. My code was being called. It's working perfectly now.

Thanks!

-Wes