getting a current value from a different script.

Hi,

I’m trying to read a value from one script and use that to determine which level to load.

I’m using the SwipeControl script by Blackish (colOOOr) which displays the levels and you can swipe them to change the picture. This has a currentValue int which is used to tell it which picture is displaying.

I than have a play button which I wanted to read the currentValue and select the level to load.

I set the currentValue in the SwipeControl scrip to a static var and then use the following code on the button.

var isPlayButton = false;

function OnMouseDown () {
	
	if (isPlayButton)
	{
		if (SwipeControl.currentValue)
		{
			SwipeControl.currentValue = 5;
			 // Load Level code//
		}
		else if (SwipeControl.currentValue)
		{
			SwipeControl.currentValue = 4;
			// Load Level code//
		}
	}
}

However, it’s not taking the value and so keeps trying to load the first level instead.

I’m hoping some fresh eye’s (or cleverer brains) can spot what I am doing wrong.

if you log currentValues it is always change and show when you swipe … it is never wait for tap selected level … so first item is level 0 and when you swipe level 4 it is already start load level 0. i got same problem too…waiting explanition

I would change ‘currentValue’ back to a non-static variable and access it by creating a public SwipeControl variable, setting it’s value to the actual SwipeControl(via Unity’s editor) and getting the current value that way.
Like this:

//a SwipeControl variable which is used to access the status of a
//game-object with a SwipeControl script attached to it.
public var swipeControl : SwipeControl;

var isPlayButton = false;

function OnMouseDown () {

    if (isPlayButton)
    {
        if (swipeControl.currentValue)
        {

            swipeControl.currentValue = 5;

             // Load Level code//
        }

        else if (swipeControl.currentValue)
        {

            swipeControl.currentValue = 4;

            // Load Level code//
        }
    }
}