void SpawnTank(int player, GameObject moveTo) { TankScript tank = Instantiate <TankScript> (tankScript); tank.GetComponent <Renderer> ().material = this.GetComponent <Renderer> ().material; tank.GetComponent <TankScript>().playerNo = playerNo; Vector3 position = moveTo.transform.position; gameplayObj.GetComponent <GamePlay> ().countrySide [target.GetComponent <HexMesh>().countryNo] = playerNo; position.y = 5.0f; tank.transform.localPosition = position; isSpawn = false; target = null; }
public void TeleportPlayer() { TankScript player = PlayerScript.playerRef.transform.Find("Tank").GetComponent <TankScript>(); player.GetComponent <Rigidbody>().velocity = new Vector3(); player.GetComponent <Rigidbody>().MovePosition(transform.position + new Vector3(0, 1f, 0)); PlayerScript.playerRef.GetComponent <PlayerScript>().startPos = transform.position; if (player.paused) { player.TeleportIn(); } for (int i = 0; i < transform.childCount; i++) { transform.GetChild(i).gameObject.SetActive(false); } }
void OnDeadActionCalled() { Debug.Log("OnDeadActionCalled"); if (netType != InstanceNetType.GameNetworkMaster) { PTC.enableUserInput = false; GetComponent <Rigidbody>().velocity = Vector3.zero; GetComponent <Rigidbody>().angularVelocity = Vector3.zero; if (netType == InstanceNetType.GameNetworkClient || netType == InstanceNetType.GameNetWorkOffline) { PTC.enableUserInput = false; PTC.UpdateWheels(0, 0); PTC.enabled = false; Destroy(TankUIRoot.gameObject); //GameNetwork.Instance.OnClientPlayerDead(); //transform.root.GetComponentInChildren<Camera>().gameObject.AddComponent<Grayscale>().shader = Shader.Find("Hidden/Grayscale Effect"); InGameVoiceSoundManager.PlayVoice(InGameVoiceSoundManager.VoiceType.Vehicle_Destroyed, InGameVoiceSoundManager.InGameVoiceLanguage(playerStateParameter.nationType)); PoolManager.CreateObject("DestroyEffect", transform.position, transform.eulerAngles); } if (netType == InstanceNetType.GameNetworkOthers) { GetComponent <Rigidbody>().isKinematic = true; } #region 炮塔飞天 if (Turret.GetComponent <MeshRenderer>() != null) { if (Turret.GetComponent <Rigidbody>() == null) { Turret.AddComponent <Rigidbody>(); } Turret.GetComponent <Rigidbody>().velocity = GetComponent <Rigidbody>().velocity *0.1f; Turret.GetComponent <Rigidbody>().AddForceAtPosition(Vector3.up * -500, Turret.transform.position); Turret.GetComponent <Rigidbody>().drag = 0.1f; Turret.GetComponent <Rigidbody>().mass = 1000; Turret.GetComponent <Rigidbody>().useGravity = true; } #endregion } else { //GameNetwork.Instance.OnPlayerDead(Util.FindPhotonPlayer (tankInitSystem.PlayerID),tankInitSystem.VehicleName); PTC.SwitchRPM = 0; PTC.UpdateWheels(0, 0); PTC.enabled = false; #region 爆炸特效 PoolManagerSpawnModule.CreateObject("DestroyEffect", transform.position, transform.eulerAngles); #endregion } //foreach(Object temp in DiedDestoryObjects){ // if(temp){ // foreach (HitBox tempHB in ((GameObject)temp).GetComponentsInChildren<HitBox>()){ // if(tempHB){ // tempHB.enabled =false; // } // } // } //} transform.tag = "Untagged"; if (TankScript.GetComponent <TankFire>().tankFireParameter.HasMachineGun) { TankScript.GetComponent <TankFire>().GetComponent <MachineGun>().CancelInvoke(); } TankScript.GetComponent <TankFire>().NowTime = 0; TankScript.GetComponent <TankFire>().enabled = false; TankScript.GetComponent <TurretController>().enabled = false; Destroy(GetComponent <Identity> ()); GameEventManager.onPlayerVehicleDestroyed(); if (GameDataManager.OfflineMode) { Destroy(transform.root.gameObject, 5f); } }
public IEnumerator Init() { PTC = GetComponent <PlayerTracksController> (); MaxHealth = Health; #region 多人模式 if (netType == InstanceNetType.GameNetworkClient) { Mine = true; } #endregion #region 单人模式 else if (netType == InstanceNetType.GameNetWorkOffline) { Mine = true; } #endregion Invoke("SwtichToNormalMode", 5); //InitAIObstacle (); if (netType == InstanceNetType.GameNetworkMaster) { PTC.SetWheels(true, false, false); InitExtraTankFires(false); transform.parent.GetComponentInChildren <TankFire> ().InitSystem(); } if (netType == InstanceNetType.GameNetworkOthers) { PTC.SetWheels(false, false, true); InitExtraTankFires(false); TankScript.GetComponent <TankFire>().InitSystem(); } yield return(new WaitForEndOfFrame()); if (netType == InstanceNetType.GameNetworkClient || netType == InstanceNetType.GameNetWorkOffline) { MainCamera = this.transform.root.GetComponentInChildren <Camera>(); PTC.SetWheels(true, true, true); StartCoroutine(InGameVoiceSoundManager.Self.Init(playerStateParameter.nationType, (InGameVoiceSoundManagerReturnValue) => { InGameVoiceSoundManager.PlayVoice(InGameVoiceSoundManager.VoiceType.Start_Battle, InGameVoiceSoundManager.InGameVoiceLanguage(playerStateParameter.nationType)); })); #region UI初始化 StartCoroutine(InitTankUISystem(ReturnValue => { TankUISystemInit(); InitExtraTankFires(true); UpdateHealthBar(); TankScript.GetComponent <TankFire>().isPlayerControl = true; TankScript.GetComponent <TankFire>().InitSystem(); TankScript.GetComponent <TankFire>().OnAmmoOut(); TankScript.GetComponent <TankFire> ().ReSetAmmoSprits(); })); #endregion StartCoroutine(CheckIfPlayerRollOver()); } }
void TankUISystemInit() { if (transform.root.GetComponentInChildren <Canvas> ()) { TankUIRoot = transform.root.GetComponentInChildren <Canvas> ().transform; } userUI = new UserUI(); userUI.HealthUI = TankUIRoot.Find("Middle/Health").GetComponent <Text>(); TankFire TF = TankScript.GetComponent <TankFire> (); TF.AmmoInfos = new Text[] { TankUIRoot.Find("Buttom/AP/AmmoCount").GetComponent <Text>(), TankUIRoot.Find("Buttom/HE/AmmoCount").GetComponent <Text>(), TankUIRoot.Find("Buttom/APCR/AmmoCount").GetComponent <Text>(), }; TF.AmmoTextures = new Image[] { TankUIRoot.Find("Buttom/AP/AmmoImage").GetComponent <Image>(), TankUIRoot.Find("Buttom/HE/AmmoImage").GetComponent <Image>(), TankUIRoot.Find("Buttom/APCR/AmmoImage").GetComponent <Image>(), }; TankUIRoot.Find("Buttom/AP/AmmoImage").GetComponent <Button>().onClick.AddListener(TankScript.GetComponent <TankFire>().SelectAp); TankUIRoot.Find("Buttom/HE/AmmoImage").GetComponent <Button>().onClick.AddListener(TankScript.GetComponent <TankFire>().SelectHE); TankUIRoot.Find("Buttom/APCR/AmmoImage").GetComponent <Button>().onClick.AddListener(TankScript.GetComponent <TankFire>().SelectApcr); TF.ReloadTimeCountDownInfo = TankUIRoot.Find("Middle/Reloading").GetComponent <Text>(); //TF.BattleLog = TankUIRoot.FindChild("Buttom/Data/Damage").GetComponent<Text>(); transform.root.GetComponentInChildren <VehicleCamera>().FireCross_Texture = TankUIRoot.Find("FireCross").GetComponent <Image>(); transform.root.GetComponentInChildren <VehicleCamera>().CrossHair = TankUIRoot.Find("Middle/CrossHair").GetComponent <Image>(); transform.root.GetComponentInChildren <VehicleCamera>().FinalPostion = TankUIRoot.Find("FireCross/FinalPostion").GetComponent <Image>(); transform.root.GetComponentInChildren <VehicleCamera>().SPGFinalPosition = TankUIRoot.Find("SPGFinal").GetComponent <Image>(); //transform.root.GetComponentInChildren<TankCamera>().CompactMirror = TankUIRoot.FindChild("FireCross/CompactMirror").GetComponent<Image>(); TankUIRoot.Find("FireCross").gameObject.SetActive(false); userUI.TeamA = TankUIRoot.Find("Middle/TeamList/TeamA").GetComponent <Text>(); userUI.TeamB = TankUIRoot.Find("Middle/TeamList/TeamB").GetComponent <Text>(); userUI.FireState = TankUIRoot.Find("Middle/FireState").GetComponent <Text> (); TF.FireStateInfo = userUI.FireState; userUI.DamageToolBar = TankUIRoot.Find("DamageTool/Data/Damage").GetComponent <Text> (); userUI.DestroyToolBar = TankUIRoot.Find("DamageTool/Data/Destroy").GetComponent <Text> (); userUI.ReloadBar = TankUIRoot.Find("Middle/ReloadBar").GetComponent <Image> (); userUI.RightBarFill = TankUIRoot.Find("Middle/RightBarFill").GetComponent <Image> (); userUI.EventCapture = TankUIRoot.Find("EventState/Capture"); userUI.CaptureProgress = userUI.EventCapture.Find("Progress").GetComponent <Text>(); userUI.EventRestore = TankUIRoot.Find("EventState/Restore"); userUI.RestoreProgress = userUI.EventRestore.Find("Progress").GetComponent <Text>(); userUI.EventRepair = TankUIRoot.Find("EventState/Repair"); userUI.RepairProgress = userUI.EventRepair.Find("Progress").GetComponent <Text>(); userUI.Message = TankUIRoot.Find("EventState/Message"); userUI.MessageContent = userUI.Message.Find("Content").GetComponent <Text>(); // TankUI.Turret = TankUIRoot.FindChild ("SmallTank/TankBody/Turret").GetComponent<Image> (); // TankUI.TankBody = TankUIRoot.FindChild ("SmallTank/TankBody/").GetComponent<Image> (); // TankUI.DamageBar = TankUIRoot.FindChild ("SmallTank/HealthBar/DamageBar").GetComponent<Image> (); // TankUI.MiniMapCamera = TankUIRoot.FindChild ("MiniMapCamera").GetComponent<Camera> (); TF.MainGunFireLoading = TankUIRoot.Find("Middle/Android/Fire/Reload").GetComponent <Image> (); //------------------------------- 手机平台 坦克NGUI 初始化 if (IsMobile) { userUI.MG = TankUIRoot.Find("Middle/Android/MachineGun").GetComponent <EventTrigger>(); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Forward").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.Forward, EventTriggerType.PointerDown)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Forward").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.CancelForward, EventTriggerType.PointerUp)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Left").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.Left, EventTriggerType.PointerDown)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Left").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.CancelLeft, EventTriggerType.PointerUp)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Right").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.Right, EventTriggerType.PointerDown)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Right").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.CancelRight, EventTriggerType.PointerUp)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Back").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.Back, EventTriggerType.PointerDown)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/Back").GetComponent <EventTrigger>().triggers.Add(MyEntry(PTC.CancelBack, EventTriggerType.PointerUp)); TankUIRoot.Find("Middle/Android/KeyBoardControllor/AddRPM").GetComponent <Button>().onClick.AddListener(PTC.AddRPM); TankUIRoot.Find("Middle/Android/KeyBoardControllor/DownRPM").GetComponent <Button>().onClick.AddListener(PTC.DownRPM); //Debug.Log("EventTrigger For KeyBoardControllor Done"); TankUIRoot.Find("Middle/Android/Fire").gameObject.AddComponent <EventTrigger>(); VehicleCamera tankCamera = transform.GetComponentInChildren <VehicleCamera>(); TankUIRoot.Find("Middle/Android/OpenFireCross").GetComponent <Button>().onClick.AddListener(tankCamera.OpenFireCross); //Debug.Log("EventTrigger For OpenFireCross Done"); //单机模式开启射击辅助 // if(!IsOnline||PlayerPrefs.GetString("AllowAutoAim")=="true") // TankUIRoot.FindChild("Android/ToggleAutoAim").GetComponent<UIEventTrigger>().onPress.Add(new EventDelegate(TankScript.GetComponent<TankFire>(),"SwtichAim")); // else // TankUIRoot.FindChild("Android/ToggleAutoAim").gameObject.SetActive(false); TankUIRoot.Find("Middle/Android/Fire").GetComponent <EventTrigger>().triggers.Add(MyEntry(TF.Fire, EventTriggerType.PointerClick)); TF.FireButton = TankUIRoot.Find("Middle/Android/Fire").GetComponent <Button>(); //TankUIRoot.FindChild("Middle/Android/Fire").GetComponent<EventTrigger>().triggers.Add(MyEntry(TF.Fire,EventTriggerType.PointerEnter)); foreach (GameObject extraTankFire in TankFires) { TankUIRoot.Find("Middle/Android/Fire").GetComponent <EventTrigger>().triggers.Add(MyEntry(extraTankFire.GetComponent <TankFire>().Fire, EventTriggerType.PointerClick)); //TankUIRoot.FindChild("Middle/Android/Fire").GetComponent<EventTrigger>().triggers.Add(MyEntry(extraTankFire.GetComponent<TankFire>().Fire,EventTriggerType.PointerEnter)); } if (playerStateParameter.vehicleType == VehicleType.SPG) { TankUIRoot.Find("Middle/Android/AutoAim").GetComponent <Button>().onClick.AddListener(TF.SetSPGAimCircleTarget); } else { TankUIRoot.Find("Middle/Android/AutoAim").GetComponent <Button>().onClick.AddListener(TF.SwtichAim); } //Debug.Log("EventTrigger For OpenFireCross Fire"); userUI.CameraJoyStick = TankUIRoot.Find("Middle/Android/CameraJoyStick/").GetComponent <Joystick>(); // FingersScript.Instance.PassThroughObjects = new List<GameObject>(); // FingersScript.Instance.PassThroughObjects.Add(TankUIRoot.FindChild("Middle/Android/OpenFireCross").gameObject); // FingersScript.Instance.PassThroughObjects.Add(TankUIRoot.FindChild("Middle/Android/Fire").gameObject); // FingersScript.Instance.PassThroughObjects.Add(TankUIRoot.FindChild("Middle/Android/AutoAim").gameObject); // FingersScript.Instance.PassThroughObjects.Add(TankUI.MG.gameObject); if (uGUI_ControllorSetting.B_EnableCameraJoyStick) { userUI.CameraJoyStick.OnJoystickMovement += tankCamera.On_JoystickMove; userUI.CameraJoyStick.OnStartJoystickMovement += tankCamera.On_JoystickMove; userUI.CameraJoyStick.OnEndJoystickMovement += tankCamera.On_JoystickStop; } else { userUI.CameraJoyStick.gameObject.SetActive(false); } } else { TankUIRoot.Find("Middle/Android/").gameObject.SetActive(false); } TankUIRoot.SetParent(null); GetComponent <PlayerTracksController>().InitUISystemForPTC(TankUIRoot); }