• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by brianchan661 · Dec 24, 2013 at 10:23 AM · gameobjectvariable

get the gameobject's variable

Hi everyone, if in my game, i instantiated number of character and each of them have a script called "A.cs",
when my game server pass a event back and every "A.cs" will listen to the event to do something,
how can i get the character's variable?
As every character have an variable "playerid", i have to check if it equal before do something.
i do not know how to fill in the if condition.
part of script that belong to the character

 void updatecharactermovement(int playeruid,string command,float a,float b,float c){
         if(command=="move"){
                 if(playeruid=xxxxxxxxxxxxxx){
             transform.eulerAngles=new Vector3(a,b,c);
                 }
         }
         if(command=="stop"){
             if(playeruid=xxxxxxxxxxxxxx){
                 transform.position=new Vector3(a,b,c);
                 
             }
         }
         
     }



part of script that instantiate characters

 private void addnewplayertolist(int memberid,string membername,float posx,float posy,float posz,float rotx,float roty,float rotz,int animationid,int movementspeed){
         
         //check if the player already in list
         bool exist=false;
         for(int i=0;i<myneighbor.Count;i++){
             if(myneighbor[i].playerid==memberid){
                 exist=true;
                 break;
             }
         }
         if(!exist){
             PhotonService.ActorData newplayer=new PhotonService.ActorData();
             newplayer.playerid=memberid;
             newplayer.playername=membername;
             newplayer.posx=posx;
             newplayer.posy=posy;
             newplayer.posz=posz;
             newplayer.rotx=rotx;
             newplayer.roty=roty;
             newplayer.rotz=rotz;
             newplayer.animationid=animationid;
             newplayer.movementspeed=movementspeed;
             
             
             GameObject model=(GameObject)Instantiate(Resources.Load("player"),new Vector3(posx,posy,posz),Quaternion.identity);
             model.name=newplayer.playername;
             model.transform.eulerAngles=new Vector3(rotx,roty,rotz);  
             
             newplayer.playeractor=model;
             myneighbor.Add(newplayer);
             model.AddComponent("otherplayercontroler");    
         }
     }
     
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Seth-Bergman · Dec 24, 2013 at 10:33 AM

you can't use a "." in a script name, stick to letters, numbers, and underscores..

anyway, like this:

 int getPlayerId = model.GetComponent<NameOfScript>().playerid;
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast object tag check? 3 Answers

Simple Dice Game - Error with Variable within an Instantiated Game Object (Prefab) - CS0118 and CS0119 Errors 2 Answers

SOLVED - Accessing a C# script value from another GameObject's JavaScript 2 Answers

Change gameObject of the VAR TARGET HELP!!! 1 Answer

Prefab problem, wont accept gameObject in var 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges