Forum

Problem in calling a function twice

Dear Coders I have a problem with calling a custom function twice in OnTick() function. Every things are alright when i call my function once. but when i call it twice every things become messed up. You can find my function below. i wrote this for detecting crossing a level. when i want to use it

Declaring Variables in Function

int Crossed ( double line1 , double line2) { static int last_direction = 0 ; static int current_direction = 0 ; if (line1>line2)current_direction = 1 ; //up if (line1<line2)current_direction = 2 ; //down if (current_direction != last_direction) //changed { last_direction = current_direction; return