x


Best way to execute a code and stop/wait for another call

Hey Guys, I've been asking a lot around here :P Because I'm trying to make a wayPoint based AI. I'm getting some nice results 'til now but I want to try other way of code this. I'm with this question since I start coding in C#. I want to know how can I execute something, like a function one time(not talking about void Start, of course) and then wait for another command to execute it again. Let's supose I have find a wayPoint and I first want to reach it to, then, search for another. A Simple print("Hello World"); within what I want is more than good. :D

Thanks from now! Sorry for any English mistakes, If you don't understand what I mean, I'll try to explain again.

more ▼

asked Mar 02 '12 at 12:29 AM

GutoThomas gravatar image

GutoThomas
593 32 46 47

(comments are locked)
10|3000 characters needed characters left

1 answer: sort oldest

I'd do it with some kind of callback. So, you have your function

void OnReachedWaypoint(Waypoint reachedThis)
{
    Debug.Log("I reached Waypoint: " + reachedThis.name);
}

(assuming that you have a type 'Waypoint' that represents a point that your AI should be approaching)

Then, where you have code that determines if the AI has reached its destination, use something like this:

if(destinationReachedThisFrame)
{
    OnReachedWaypoint(currentWaypoint);
}
more ▼

answered Mar 02 '12 at 12:35 AM

syclamoth gravatar image

syclamoth
14.8k 7 15 80

That first function should be 'void OnReachedWaypoint', sorry. There's a rather frustrating Qato bug going around right now that stops edits from showing up.

Mar 02 '12 at 12:37 AM syclamoth

Got it! I guess I'll can get some updates with the code now. :D Thanks for the (fast) reply!

Mar 02 '12 at 12:50 AM GutoThomas
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x58
x18
x17

asked: Mar 02 '12 at 12:29 AM

Seen: 404 times

Last Updated: Mar 02 '12 at 12:50 AM