x


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.

more ▼

asked Mar 26 '12 at 04:22 PM

Dengog gravatar image

Dengog
0 1 2 3

Which variable are you having a problem with?

The more specific you are, the better the chances we'll be able to help.

Mar 26 '12 at 04:58 PM rutter
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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

more ▼

answered Mar 26 '12 at 06:36 PM

Dengog gravatar image

Dengog
0 1 2 3

(comments are locked)
10|3000 characters needed characters left

I found the problem at my own, it's only possible with a transform instead of the gameobject newPlayer

more ▼

answered Mar 26 '12 at 06:36 PM

Dengog gravatar image

Dengog
0 1 2 3

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1259
x824
x153

asked: Mar 26 '12 at 04:22 PM

Seen: 348 times

Last Updated: Mar 26 '12 at 06:36 PM