void Update() { if (!photonView.isMine) { return; } isDead =currentPawn==null||currentPawn.isDead; if(isDead){ Pawn[] prefabClass= PlayerManager.instance.avaiblePawn; SendDelayedExternal(); respawnTimer-=Time.deltaTime; // Debug.Log ("Dead"); if(respawnTimer<=0&&isStarted){ respawnTimer=respawnTime; currentPawn =PlayerManager.instance.SpawmPlayer(prefabClass[selected],team); PVPGameRule.instance.Spawn(team); AfterSpawnSetting(currentPawn,PawnType.PAWN,team); prefabBot =PlayerManager.instance.avaibleBots[selectedBot]; prefabGhostBot =PlayerManager.instance.ghostsBots[selectedBot]; } canSpamBot=true; }else{ Ray centerofScreen =Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); RaycastHit hitinfo; if(robotPawn==null){ robotTimer-=Time.deltaTime; if(robotTimer<=0&&canSpamBot){ if(Input.GetButton("SpawnBot")){ if(Physics.Raycast(centerofScreen, out hitinfo,50.0f)){ if(ghostBot==null){ GameObject ghostGameObj = Instantiate(prefabGhostBot,hitinfo.point,currentPawn.transform.rotation) as GameObject; ghostBot =ghostGameObj.GetComponent<GhostObject>(); } ghostBot.myTransform.position = hitinfo.point; ghostBot.myTransform.rotation = currentPawn.transform.rotation; if(Physics.SphereCast(hitinfo.point+Vector3.up*ghostBot.size,ghostBot.size,Vector3.up,out hitinfo,100.0f)){ //Debug.Log (hitinfo.collider); if(canSpawnBot){ ghostBot.MakeBad(); //Debug.Log (ghostBot.myRenderer.sharedMaterial.color); } canSpawnBot=false; }else{ if(!canSpawnBot){ ghostBot.MakeNormal(); //Debug.Log (ghostBot.myRenderer.sharedMaterial.color); } canSpawnBot=true; } } } if(Input.GetButtonUp("SpawnBot")){ if(ghostBot!=null&&canSpawnBot){ Vector3 spamPoint =ghostBot.transform.position; spamPoint.y+= 30; robotPawn =(RobotPawn)PlayerManager.instance.SpawmPlayer(prefabBot,spamPoint,ghostBot.transform.rotation); //Debug.Log("robot spawn"+robotPawn); AfterSpawnSetting(robotPawn,PawnType.BOT,team); canSpawnBot=false; } //Debug.Log("destory chost"); Destroy(ghostBot.gameObject); } } } if(inBot){ useTarget= null; if(Input.GetButtonDown("Use")){ ExitBot(); } }else { if(!inBot&&robotPawn!=null){ if(currentPawn.curLookTarget!=null&¤tPawn.curLookTarget.gameObject==robotPawn.gameObject){ if(Input.GetButtonDown("Use")){ EnterBot(); } } } if(currentPawn.curLookTarget!=null){ useTarget = currentPawn.curLookTarget.GetComponent<UseObject>(); if(useTarget!=null&&(currentPawn.myTransform.position-useTarget.myTransform.position).sqrMagnitude<SQUERED_RADIUS_OF_ACTION&&Input.GetButtonDown("Use")){ useTarget.Use(currentPawn); } }else{ useTarget= null; } //Debug.Log (currentPawn.curLookTarget); } if(Input.GetButton("Fire2")){ currentPawn.ToggleAim(true); if(robotPawn!=null){ robotPawn.ToggleAim(true); } }else{ currentPawn.ToggleAim(false); if(robotPawn!=null){ robotPawn.ToggleAim(false); } } if(Input.GetButtonDown("Weapon1")){ currentPawn.ChangeWeapon (0); if(robotPawn!=null){ robotPawn.ChangeWeapon (0); } } if(Input.GetButtonDown("Weapon2")){ currentPawn.ChangeWeapon (1); if(robotPawn!=null){ robotPawn.ChangeWeapon (1); } } if(Input.GetButtonDown("Weapon3")){ currentPawn.ChangeWeapon (2); if(robotPawn!=null){ robotPawn.ChangeWeapon (2); } } } }
public void RPCAfterSpawnSetting(int viewid,int type,int iteam) { PawnType pType = (PawnType)type; //Debug.Log (viewid); Pawn pawn =PhotonView.Find (viewid).GetComponent<Pawn>(); team = iteam; pawn.player = this; pawn.team = this.team; switch (pType) { case PawnType.PAWN: currentPawn = pawn; break; case PawnType.BOT: robotPawn = (RobotPawn)pawn; break; } }