Search Unity

HOTween sequence question...

Discussion in 'Scripting' started by AngryOrange, Nov 30, 2012.

  1. AngryOrange

    AngryOrange

    Joined:
    Jan 30, 2012
    Posts:
    103
    Hi
    I have 4 objects . I made one tween with position...

    Code (csharp):
    1.  
    2. TweenParms parms = new TweenParms();
    3. parms.Prop("position", new Vector3(transform.position.x + takeRandomX() , transform.position.y + takeRandomY()));
    4.  
    5. float takeRandomY()
    6.     {
    7.         randomY = Random.Range(-0.8f, 0.8f);
    8.         return randomY;
    9.     }
    10.  
    than I add this to the sequence for 4 different objects. Why they are moving to random position each time I start app but all of them in the same position .

    Code (csharp):
    1.        
    2.                objectMove  = new Sequence();
    3.        
    4.         objectMove.Insert(1, HOTween.To(object1.transform, 4, parms));
    5.         objectMove.Insert(1, HOTween.To(object2.transform, 4, parms));
    6.         objectMove.Insert(1, HOTween.To(object3.transform,4,  parms));
    7.         objectMove.Insert(1, HOTween.To (object4.transform,4, parms));
    I want them to move in 4 different positions.... What I made wrong ?
     
    Last edited: Nov 30, 2012
  2. AngryOrange

    AngryOrange

    Joined:
    Jan 30, 2012
    Posts:
    103
    anyone?
     
  3. Demigiant

    Demigiant

    Joined:
    Jan 27, 2011
    Posts:
    3,242
    Hi AngryOrange,

    in your Sequence you're adding 4 Tweeners that all share the same exact parms, which include the same exact position to reach, so they will all move to the same point.

    You should do this instead, making the prop relative (see the last "true" parameter in the Prop parm) in order to avoid having to type "transform.position.x/y":
    Code (csharp):
    1.  
    2.  objectMove.Insert(1, HOTween.To(object1.transform, 4, new TweenParms()
    3.   .Prop("position", new Vector3(takeRandomX() , takeRandomY()), true)
    4. ));
    5. objectMove.Insert(1, HOTween.To(object2.transform, 4, new TweenParms()
    6.   .Prop("position", new Vector3(takeRandomX() , takeRandomY()), true)
    7. ));
    8. objectMove.Insert(1, HOTween.To(object3.transform, 4, new TweenParms()
    9.   .Prop("position", new Vector3(takeRandomX() , takeRandomY()), true)
    10. ));
    11. objectMove.Insert(1, HOTween.To(object4.transform, 4, new TweenParms()
    12.   .Prop("position", new Vector3(takeRandomX() , takeRandomY()), true)
    13. ));
    14.