Unity Community


Results 1 to 8 of 8

  1. Posts
    247

    iTween onComplete in C#

    So I'm using iTween moveTo() function in C# and trying to get the onComplete paramter to call my defined function when the iTween is complete.

    So I have:

    iTween.moveTo(selectedObj, 1, 0, pos, null, "OnMoveComplete", "");

    Then in my class I have:

    void OnMoveComplete(object obj)
    {
    Debug.Log("Testing");
    }


    I never see "Testing" in the console. What am I doing wrong?


  2. Location
    Baltimore, Maryland, United States
    Posts
    674

    Re: iTween onComplete in C#

    Quote Originally Posted by Rick
    So I'm using iTween moveTo() function in C# and trying to get the onComplete paramter to call my defined function when the iTween is complete.

    So I have:

    iTween.moveTo(selectedObj, 1, 0, pos, null, "OnMoveComplete", "");

    Then in my class I have:

    void OnMoveComplete(object obj)
    {
    Debug.Log("Testing");
    }


    I never see "Testing" in the console. What am I doing wrong?
    I plan on putting together even better documentation with the release of iTween 2.0 to address questions such as this but let me explain what's going on in your situation.

    iTween is being attached to 'selectedObj' and therefore is attempting to call 'OnMoveComplete' on that object. To solve this, also pass in 'onCompleteTarget' and give it a refrence to this GameObject.

    Cool?
    Do everything as well as you can...
    http://itween.pixelplacement.com/


  3. Posts
    247
    Ah, very cool! I created a script in the target object that would route the call back to my main script, but this will be much better. Thanks!! Keep up the good work.


  4. Posts
    142
    Can someone please give me example call for that?
    In my case i wrote that:

    Code:  
    1. iTween.moveTo(obj, 1f, null, new Vector3(obj.transform.position.x, -1.5f, obj.transform.position.z), iTween.EasingType.linear, "OnComplete", null, obj, obj);

    But it doens´t work. I don´t know which reference you mean. Any help on that? Thanks a lot


  5. Location
    Zürich, Switzerland
    Posts
    26,572
    The way you have written it it will call OnComplete on the object 'obj'
    If you want it to call it on this gameobject, you need to replace , null, obj with , this, obj for example


  6. Location
    France
    Posts
    17
    Hi, I have some troubles with the callback function.

    What can I do if the script in which I use iTween is not attached to the gameobject I move (in fact the callfunction is not on a script attached to any gameObject)?

    I want to modify a boolean if the movment is finished (the change occurs in the callback function) but this boolean and the callback function are in the script that is not linked to any gameobject (it's a camera mod script which is instancied by a camara mod's manager)


  7. Location
    Baltimore, Maryland, United States
    Posts
    674
    iTween can only call a function that is attached to a GO. You can target any GO you want - is there any chance you can just make a helper call to this script you need? Maybe another static method that could be called somehow?
    Do everything as well as you can...
    http://itween.pixelplacement.com/


  8. Location
    France
    Posts
    17
    Ok thanks, it should work (but I don't like to use too many static functions/variables that should be private and localised only in the class linked to it the logical way).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •