Hello.
I’m making a game and I want to do an action, for example print a text in the console, but only print the text one time, when I’m moved a determined distance. I made this script but does not work:
(I use this script also for show the Walked distance in the screen.)
var WalkedDistance : float = 0;
var lastPosition : Vector3;
var style : GUIStyle;
function Start()
{
lastPosition = transform.position;
}
function Update() {
WalkedDistance += Vector3.Distance(transform.position, lastPosition);
lastPosition = transform.position;
if(WalkedDistance >= 100){ //This does not work
print("TEXT");
}
}
function OnGUI()
{
GUILayout.Label("Walked distance = " + WalkedDistance);
}
I think in it, but if I use this script, then, the message will print infinite times and I want to print the message only one time. Would you know how to do it? c:
Thanks for reply.
There was no reply box in the message you sent me, not sure why.
So I will answer here.
If this is actually a project, then it sounds like school homework and you should do it yourself.
If you dont know how to declare a boolean, or what one even is, you need to read a book, not ask questions on a forum.
Thats the best advice I can give you.