I’m a little irritated… i tryed all example, all of all, but nothing!
i have an object called DirectGUI, in this object i have a script called ScriptGUI, ok, in this script i have a variable called Name, that i can edit with a textbox.
now i have another object called FPSPlayer, This is not in the game, will be only created at run-time, in this object i have a script called Player, end i have a variable called Nick, i want that in function Start, the var Nick, will be the same of the var Name in the other script, in the other object, but i got lot of errors… i tryed this at last:
function Start() {
object=GameObject.Find(“DirectGUI”);
script = object.GetComponent(“ScriptGui”);
nick = script.Name;
}
but i got “Name is not a member of Unity.Component”…
and i tryed also other example but didn’t work… why? :(
i want simply acces a variable in another script in another object… i repeat, the object FPSPlayer, isnt in the game, is only a prefab that will be created in the game… and after created i want that Nick will be the same of Name…
Did you declare script to be a particular type or were you letting js do it. The type returned from your line is Component and it needs to be ScriptGui so you can access the variables.
On a different subject. Variable names should start with a lower case character. That has nothing to do with your error, its just a standard way of coding.
Class and function names start with capitals.
First re-name your variable in the other script, it’s going to be confusing to call it ‘Name’, I’ll call it ‘banana’ for now. Make sure it is not declared as a private var.
So in DirectGUI’s Script put:
var banana : string = "";
In the other object’s script, put:
private var DirectGUI : ScriptGUI;
function Start() {
DirectGUI = FindObjectOfType(ScriptGUI);
}
… now, from the other object’s script, you access your variable ‘banana’ in DirectGUI’s script like this:
i dont want open another thread, i will change the name of the topic, but i cant figure how the RPC of the network work when a new player join… it work well… but i dont know…how xD
for example…
join player 1;
join player 2;
now join the player3, how he know the number of player already in the game and create this? with the buffer? and if i want clear the buffers of the RPCs, when a new player join, he will not see other player? ???
if someone will give me a good explanation… thanks, Mauro
Check out the documentation part for networking, especially Network.Instantiate and the RPC Modes (buffered calls generally must be called by the server to be buffered for other clients)
Don’t expect people to give you answers on that unprecise questions.
If you have a specific problem with your implementation, please post detailed information and code for it.
But if you have not even an idea on how to start, check the documentation and Network Example project in the support section of the website to get basic ideas on how anything works at all.