Unity Community


Results 1 to 3 of 3

  1. Location
    Mumbai
    Posts
    55

    Invoke with parameters

    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

    invoke("TestTimerbj1bj2",0.5f);????
    ABGamerss
    Games: Physics Orb's | Memory Master | Learning Is Fun: Shapes
    Follow: Twitter | FaceBook Pages: ABGamerss | PhysicsOrb's


  2. Location
    Australia
    Posts
    129
    Hi

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

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

    Code:  
    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
    3.  
    4. function Start()
    5. {
    6.      Invoke("TestTimer", 0.5);
    7. }
    8.  
    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.

    Cheers
    Unity 3 F5 with Unity Iphone + iPhone 3GS

  3. Volunteer Moderator
    Posts
    23,697
    Instead of Invoke, use a coroutine, and use yield WaitForSeconds to implement the delay.

    --Eric
    SpriteTile: new tile system that works seamlessly with Unity 4.3 sprites
    FlyingText3D: dynamic 3D text with TTF fonts | Vectrosity: fast & easy line drawing
    Nifty utilities! Stitch terrains together - runtime model importing - file browser - fractal landscapes

Posting Permissions

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