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*.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"); *
-
}*
-
}*