- Home /
Can't Access a Prefab
Hi, I'm actually working on a project with SmartFoxServer and Unity3D. Here the little snippet: void OnPublicMessage(BaseEvent e) {
User sender = (User)e.Params["sender"];
message = (string)(e.Params["message"]+sender.Name);
string[] cmd = message.Split(':');
if (cmd[0]=="New" && cmd[1]==sender.Name) {
GameObject newPlayer = Instantiate(prefab,new Vector3(2,2,2), Quaternion.identity) as GameObject;
InformationSheet Info = newPlayer.GetComponent<InformationSheet>();
Info.UserName=cmd[1];
}
}
When I run the project it creates a new gameobject (prefab), but the variable in the script ob this gameobject doesn't change.
BTW: The message is "New:Guest#XX" so that script knows that a new player named Guest#XX connected.
Which variable are you having a problem with?
The more specific you are, the better the chances we'll be able to help.
Answer by Dengog · Mar 26, 2012 at 06:36 PM
oh sorry is the Info.UserName variable: public class InformationSheet : MonoBehaviour {
public string UserName="";
public void SetName(string Name) {
UserName=Name;
}
} I also tried with a setter function, but the same problem
Answer by Dengog · Mar 26, 2012 at 06:36 PM
I found the problem at my own, it's only possible with a transform instead of the gameobject newPlayer