Author Topic: How could I move the sprite for amount of distance every time I call the method?  (Read 2188 times)

neunundneunzig

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
Image a counter, every time player click a button or some other function pass the variable to add the counter, this sprite will go forward.

Is there any way I can just input the movement distance in tween component? Or I have to use the script to hard code the movement distance?

Right now tween of NGUI could only assign the start position and destination. But I want the vector variable.

Thanks.

OnlineCop

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 51
    • View Profile
You can modify the tween's .to value. When you do a TweenPosition.Begin(go, duration, newPosition), its '.from' value is the GameObject's current location and its '.to' value it the 'NewPosition' (it's all based off of its .localPosition, not world .position).

If you know the new location (basically, its .to position plus any new movement distance you add to it), I would just update the '.to' value:
  1. Vector3 currentPosition = myPositionTween.to;
  2. Vector3 deltaPosition = new Vector3(0f, 0, 100f); // Or whatever movement distance you want
  3. Vector3 updatedPosition = currentPosition + deltaPosition;
  4.  
  5. myPositionTween.to = updatedPosition;
  6.  

This will 'tack on' 100 pixels (along z) to the current position tween.

So if you have a counter that should fill to '100' and the player hits their button twice really quick, it will start to lerp to '200' and then just continue (without stuttering or restarting) straight to '300'.

Is that what you're looking for?

neunundneunzig

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
    • View Profile
that's the hard code solution

I thought it could be done in NGUI component, like there is a public variable called "distance(x, y, z)" then you just need to fill the number to tell the object how much to move.


But thanks anyway.