iTween onComplete in C#

Discussion in 'Scripting' started by RickP, May 23, 2010.

  1. RickP

    RickP

    New Member

    Joined:
    Apr 4, 2010
    Messages:
    247
    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. pixelplacement1

    pixelplacement1

    New Member

    Joined:
    Aug 19, 2009
    Messages:
    674
    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?
  3. RickP

    RickP

    New Member

    Joined:
    Apr 4, 2010
    Messages:
    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. yosh

    yosh

    Member

    Joined:
    Mar 13, 2009
    Messages:
    142
    Can someone please give me example call for that?
    In my case i wrote that:

    Code (csharp):
    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. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    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. solmyr-fr

    solmyr-fr

    Member

    Joined:
    Jun 18, 2009
    Messages:
    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. pixelplacement1

    pixelplacement1

    New Member

    Joined:
    Aug 19, 2009
    Messages:
    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?
  8. solmyr-fr

    solmyr-fr

    Member

    Joined:
    Jun 18, 2009
    Messages:
    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).