Author Topic: Call When Finished reference to gameobject  (Read 3232 times)

sjunnesson

  • Guest
Call When Finished reference to gameobject
« on: February 06, 2013, 12:52:17 PM »
Hi,

I need to call a function that will Destroy the gameobject once a Tween has finished. I have it setup like this right now.
  1. // set the gameobject that will recieve the callback
  2. btnTween.eventReceiver=gameObject;
  3. // set the function that will be called
  4. btnTween.callWhenFinished="destroyObject";
  5. // set the start position to the current position
  6.  

The function that is called looks like this.

  1. function destroyObject(sender:GameObject){
  2.         print("DESTROY ME");
  3.         Destroy(sender);
  4. }

The problem I have is that there is no reference to the sender so the destroyObject function dosnt know which object to destroy. With Button Messages it seems a reference is passed through so I thought the same thing was valid for the onFinished function. If create the destroyObject function likes this instead it works nicely printing out the text "DESTROY ME" so the calling and naming seems to be ok just need to pass the reference through.

  1. function destroyObject(){
  2.         print("DESTROY ME");
  3. }


Any ideas on how to work around this?
« Last Edit: February 06, 2013, 02:13:16 PM by sjunnesson »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Call When Finished reference to gameobject
« Reply #1 on: February 06, 2013, 10:17:42 PM »
The callback function's parameter is the tween that triggered the callback. You can get the gameobject reference from it.

sjunnesson

  • Guest
Re: Call When Finished reference to gameobject
« Reply #2 on: February 07, 2013, 04:20:31 PM »
Thanks for the help. Turned out to be the simplest misstake and now it works good to get the gameobject reference.