plaese help me (global var)

hi I have 2 script. script 1 name is: slideshow and second script name is : nextimage

so i want in the nextimage script , when mousedown changed x value to other script(slideshow) x=x+1 how to write this?

you could either store a reference to the other script and access it directly or you make the variable in question static and call it by type.variable from anywhere.

please wirte a basic example

Look up some tutorials on how to use the inspector.

Look up GetComponent in the Script Referance.

Look up ‘Singleton’ in google - might want to limit searches to C#.

i working with java script
and i need a basic example for static value an change a value in to script .

please write here
thanks

I had some trouble understanding GetCompnent functionality but its extremely useful and at this point its hard to imagine how I have gotten as far as I did without. Here is the great reply I got when I was confused about it I think it will help you a great deal http://forum.unity3d.com/threads/121798-Really-Stuck-and-Mildly-Confused-(GetComponent-and-function-calls-across-scripts)

Just some advice, asking for code is not the same as asking for help with your code, people tend to less receptive to the idea of handing someone code mainly because every project has its own configuration so any given line of code may or may not work directly and people dont like to get ‘this doesnt work responses’.

For a good response from the community its best to read/learn/search and ultimately if your stuck post what you got. Its usually easier to come up with a applicable example to someones specific project when you have something to look at.

you can access the function of 1 script in other by globally declaring first like
if you want to access the function of slideshow in nextimage then:
var slideshow:slideshow;
script2{

slideshow.function-name();

}
i hope this will help you

GetComponent we use when we have the both script on same object

i think xguild meant to retrive the script component with getcomponent from an object the script in need has a reference to (wich could be set in the inspector).

You can (and should) use GetComponent even if scripts are on different objects.

–Eric

In this instance, assuming both scripts are on the same object, I wouldn’t even bother with GetComponent.

Instead try BroadcastMessage:

slideshow script:

var x = 0;

function IndexUp(){
	x += 1;	
}

nextimage script:

function Update (){
	if (Input.GetMouseButtonDown(0)){
		BroadcastMessage ("IndexUp");	
	}
}

thanks you