CallBacks

Updated on June 5, 2017 in [A] Unity Scripting
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
13 on June 5, 2017

So trying to do that callBack, that was mentioned to me earlier. It’s not working, as I’m obviously not calling it correctly. I’d appreciate help neatening this up and getting it working please. This is what I have so far.

public delegate void GetMyText (Text time);
public GetMyText getMyTextCallback;
private Text timerCountDown;

void Start()
{
GetMyTextDelay ();

}

public void GetMyTextDelay()
{
getMyTextCallback (timerCountDown);
}

public void WeFoundText(GetMyText _getMyText, Text time)
{
timerCountDown = time;
time = GameObject.FindWithTag(“Time”).GetComponent<Text>();
Invoke (“GetMyTextDelay”,5);
getMyTextCallback = _getMyText;
}

  • Liked by
Reply
12 on June 5, 2017

What is not working?
You seem to be calling everything fine in this code.

on June 5, 2017

Sorry can’t believe I forgot to mention the specifics. 

time = GameObject.FindWithTag(“Time”).GetComponent<Text>();

Basically I’m trying to delay the findwithtag, as the object searching is in the scene a tad bit before the object with the tag. It’s not delaying the findwithtag. It’s still doing it instantly in start. 

Guru
on June 5, 2017

That’s because you’re calling it in start.
You should be calling the WeFoundText method instead.

on June 5, 2017

I’m sorry this is the first I’ve written a callback and on my own. Are you able to elaborate a little bit for a noob please? 

Wise
on June 5, 2017

So this code you posted sits on the Player (which is spawned)?

on June 5, 2017

No the game manager object that is already in the scene.

on June 5, 2017

If I put it on the player I don’t need to worry about callbacks. It’s just that it’s a multiplayer game and I was going to add to game manger a way to keep track of the time so even if a new player is spawned half way through they still keep track of the time accurately.

Wise
on June 5, 2017

So, what you’ve done with callbacks now is literally nothing, you are still calling it in the start.

Wise
on June 5, 2017

And will every Player have a time Text object? Since here you are looking for only one, which one?

on June 5, 2017

Then I misunderstand how they work lol. I thought it would be called and then wait for x amount of time to actually do the function within the callback. 

Wise
on June 5, 2017

Nope.

Show more replies
  • Liked by
Reply
Cancel