1. We've introduced thread tags, search within a thread and similar thread search. Read more here.
    Dismiss Notice
  2. We've released our first Timeline Experimental Preview, our new tool for creating cutscenes and more! To check it out click here.
    Dismiss Notice
  3. All Unity Pro perpetual license customers: your special offer to subscribe is ready! Click here.
    Dismiss Notice
  4. Unity 5.5 is now released.
    Dismiss Notice
  5. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  6. Unity 5.6 beta is now available for download.
    Dismiss Notice
  7. Get prepared for the Tizen Mobile App Incentive Program! Read more about the upcoming program here.
    Dismiss Notice
  8. Enter the Microsoft Developer Challenge for a chance to win prizes. Read more about it here.
    Dismiss Notice

Invoke with parameters

Discussion in 'iOS and tvOS' started by abgamers, Nov 23, 2010.

  1. abgamers


    Dec 22, 2009
    Hi Im trying to invoke a function which is having 2 parameters,
    can anyone tell me how to use it

    say for example im trying to invoke following function

    void TestTimer (gameObject obj1, gameObject obj2){

    so how the invoke is going to be

  2. dcp468


    Aug 25, 2009

    Based on the Invoke documentation you cannot include parameters http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Invoke.html.

    If you just have two gameObjects and they never will change then just access them in the TestTimer function/method

    Code (csharp):
    1. var gameObject1 : gameObject;    // Drag gameobject 1 to this variable in the Unity Editor
    2. var gameObject2 : gameObject;    // Drag gameobject 2 to this variable in the Unity Editor
    4. function Start()
    5. {
    6.      Invoke("TestTimer", 0.5);
    7. }
    9. function TestTimer()
    10. {
    11.      // perform whatever actions you want on the 2 gameobjects
    12.      gameObject1.performSomeAction();
    13.      gameObject2.performSomeOtherAction();
    14. }
    If you need to modify 2 gameobjects every 0.5 seconds and the 2 gameobjects can change to be other instances because maybe you have 20 different game objects in your game then that's going to be a little different.

  3. Eric5h5


    Volunteer Moderator Moderator

    Jul 19, 2006
    Instead of Invoke, use a coroutine, and use yield WaitForSeconds to implement the delay.