Very strange script problem variable change with no reason

I have very strange script problem that i totally do not understand. It started with this problem/post: [SOLVED] Why does this code not create a reaction, variable change for no reason - Unity Engine - Unity Discussions

I have done some testing and really do not understand what is happening.

Here is code:

Definition:
private float testing;

voidAwake() {
testing = -99.9f;

public void OneFingerDragProcess (Gesture gesture) {
print ("testing: " + testing);

There is an if-statement before the print statement. The “OneFingerDragProcess” is EasyTouch. The “testing” statements is the only places that they are in the code.

When i drag the object and trigger testing i get the following results:

testing: -99.9
testing: 0
testing: -99.9
testing: 0
testing: -99.9
testing: 0

What i do not understand is why variable testing is changing value all the time. Again, there is only the above places were “testing” is used in the whole project.

I have other similar problems with other variables as well.

I know this is a strange problem and would just want to ask if anyone seen anything similar?

The code were the drag is happening is displayed below. Except this the only place other were the “testing” is used is the definition and in Awake.

I am puzzled.

//=======================================================================================//
    //                                 OneFingerDragProcess                                  //
    //=======================================================================================//
  
    public void OneFingerDragProcess (Gesture gesture) {

        if (!isCardProtected) { // DO NOT PROCESS IF CARD IS PROTECTED, SET IN "SingleTap"

            if (gesture.touchCount == 1) { // CHECK NUMBER OF FINGERS ON THE DISPLAY
              
                if (selected_GameObject != null) { // Make sure that the code is processed ONLY is object is selected
                  
                    if (!fingerSelectionMode) { // Finger draw selection
                      
                        if (selected_GameObject.tag != "Background") {
                          
                            // catch possible exception errors
                            try {
                                selected_GameObject.transform.position = Camera.main.ScreenToWorldPoint (gesture.position);
                            } catch {
                              
                                return;
                            }
                          
                            Vector3 temp = selected_GameObject.transform.position;
                            temp.z = nrOfCardsInTheGame - 1; //5;
                            selected_GameObject.transform.position = temp;
                          
                            //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//
                            // Manage the draw-point so the object is dragged from the point of click
                            Vector3 worldPoint = Camera.main.ScreenToWorldPoint (Input.mousePosition);     //gesture.position);
                            Vector3 posE = selected_GameObject.transform.position;
                            posE.x = worldPoint.x - delta.x;
                            posE.y = worldPoint.y - delta.y;
                            selected_GameObject.transform.position = posE;
                            //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//

                            // SET UP Y-BASED LIMITS FOR CARDS
                            //                    float redPlayerY = redLocalMultiplayerLinePosition.y + cardHeight;         //     -2.7f
                            //                    float bluePlayerY = blueLocalMultiplayerLinePosition.y - cardHeight;     //     2.7f
                          
                          
                            // Check & correct if object is outside of screen boundaries
                            float finalWidth = maxWidth - cardWidth;
                            float finalHeight = maxHeight - cardHeight;

                            // ADJUST THE EDGE BASED ON TYPE OF GAME
                            if (selected_GameObject.transform.position.x <= -finalWidth) {
                                selected_GameObject.transform.position = new Vector3 (-finalWidth, selected_GameObject.transform.position.y, selected_GameObject.transform.position.z);
                            } else if (selected_GameObject.transform.position.x >= finalWidth) {
                                selected_GameObject.transform.position = new Vector3 (finalWidth, selected_GameObject.transform.position.y, selected_GameObject.transform.position.z);
                            }
                          
                            //                    if (gameBoardType == "DoNormal") {
                            if (selected_GameObject.transform.position.y <= -finalHeight) {
                                selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, -finalHeight, selected_GameObject.transform.position.z);
                            } else if (selected_GameObject.transform.position.y >= finalHeight) {
                                selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, finalHeight, selected_GameObject.transform.position.z);
                            }

                            if (gameMode == "LOCAL MULTIPLAYER") {
                                //print ("useProtectionZoneAtMultiplayer:       >> " + useProtectionZoneAtMultiplayer);

                                if (useProtectionZoneAtMultiplayer) { // THIS IS TO DISABLE THE PROTECTED QUADRANTS IN MULTIPLAYER MODE

                                    whatPlayerIsActive = PlayerPrefs.GetString ("ACTIVE PLAYER");
                                    print ("testing: " + testing);
                                    if (whatPlayerIsActive == "BLUE") {
                                        print ("GO-y: " + selected_GameObject.transform.position.y + " redPlayerY: " + redPlayerY);
                                        if (selected_GameObject.transform.position.y >= 1.9f) { //redPlayerY) {
                                            selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, 1.9f, selected_GameObject.transform.position.z);
                                            //selected_GameObject.transform.position = new Vector3 (1f, 1f, 0f);
                                        }
                                    } else if (whatPlayerIsActive == "RED") {

                                        if (selected_GameObject.transform.position.y <= -1.9f) { //bluePlayerY) {
                                            //selected_GameObject.transform.position = new Vector3 (-1f, -1f, 1f);
                                            selected_GameObject.transform.position = new Vector3 (selected_GameObject.transform.position.x, bluePlayerY, selected_GameObject.transform.position.z);
                                        }
                                    }
                                }
                            }
                        }
                    } else {

                        selectObjectWithFingerDraw ();
                    }
                }
            }
        }
    }

If youd like, post an example project for us to go in and try to see what the issue is.
I dont think there is enough information for us to help you otherwise.

I finally, after hours of searching, the problem.

I changed:

public class LocalCoinWallet : GameEngine_Script {

to:

public class LocalCoinWallet : MonoBehaviour {

…and it worked again.

I still do not understand why this is a problem as i do not reference the GameEngine_Script variables from LocalCoinWallet but it still effect a few variables.

Anyhow, now it works.