//Variables End_____________________________________ void Awake() { //Этот скрипт будет работать только для других персонажей. //Нам не нужен бар здоровья для своего игрока в нашей игре. if (!isLocalPlayer) { myTransform = transform; myCamera = Camera.main; //Access the HealthAndDamage script. //Transform triggerTransform = transform.FindChild("Trigger"); HDScript = GetComponent<HealthAndArmor>(); //The font colour of the GUIStyle depends on which team the //player is on. if(myTransform.tag == "BlueTeam") { myStyle.normal.textColor = Color.blue; } if(myTransform.tag == "RedTeam") { myStyle.normal.textColor = Color.red; } myStyle.fontSize = 12; myStyle.fontStyle = FontStyle.Bold; //Allow the text to extend beyond the width of the label. myStyle.clipping = TextClipping.Overflow; } else { enabled = false; } }
// Use this for initialization private void Start() { //Getting the reference to the health and armor component for our player switch (this.playerID) { case Players.P1: this.ourHealthAndArmor = PlayerShipController.p1ShipRef.ourHealth; break; case Players.P2: this.ourHealthAndArmor = PlayerShipController.p2ShipRef.ourHealth; break; default: this.ourHealthAndArmor = PlayerShipController.p1ShipRef.ourHealth; break; } this.UpdateSliders(); }
//Function called when this object collides with another collider private void OnTriggerEnter(Collider collision_) { //Checking to see if the object that hit this pickup is a player ship if (collision_.gameObject.GetComponent <HealthAndArmor>()) { //Creating a variable to hold the health and armor component that we hit HealthAndArmor hitArmor = collision_.gameObject.GetComponent <HealthAndArmor>(); //If the hit object is for player 1 ship if (hitArmor.objectIDType == AttackerID.Player1) { //Telling the player 1 ship to restore shields by our amount to restore PlayerShipController.p1ShipRef.shipShield.RestoreShields(this.shieldToRestore); //Disabling our collider component this.GetComponent <Collider>().enabled = false; //Setting the player ship to follow this.playerShipTransform = PlayerShipController.p1ShipRef.transform; //Setting our default scale this.defaultScale = this.transform.lossyScale; //Starting the animation this.isAnimating = true; //Telling our sound emitter to play the pickup sound this.GetComponent <ExtraSoundEmitterSettings>().ownerAudio.Play(); //If the player ship's shield collider is disabled, we enable it again if (!PlayerShipController.p1ShipRef.shipShield.gameObject.activeInHierarchy) { PlayerShipController.p1ShipRef.shipShield.gameObject.SetActive(true); } } //If the hit object is for player 2 ship else if (hitArmor.objectIDType == AttackerID.Player2) { //Telling the player 2 ship to restore shields by our amount to restore PlayerShipController.p2ShipRef.shipShield.RestoreShields(this.shieldToRestore); //Disabling our collider component this.GetComponent <Collider>().enabled = false; //Setting the player ship to follow this.playerShipTransform = PlayerShipController.p2ShipRef.transform; //Setting our default scale this.defaultScale = this.transform.lossyScale; //Starting the animation this.isAnimating = true; //Telling our sound emitter to play the pickup sound this.GetComponent <ExtraSoundEmitterSettings>().ownerAudio.Play(); //If the player ship's shield collider is disabled, we enable it again if (!PlayerShipController.p2ShipRef.shipShield.gameObject.activeInHierarchy) { PlayerShipController.p2ShipRef.shipShield.gameObject.SetActive(true); } } //If an enemy hits this component nothing happens } }
//Function called when this object is created private void Awake() { //Getting the movement component references this.ourFreeMovement = this.GetComponent <FreeMovementFlight>(); this.ourRailMovement = this.GetComponent <RailMovementFlight>(); //Getting our controller input based on which player this is switch (this.playerController) { case Players.P1: //Making sure there's not already a static reference to the p1 ship if (p1ShipRef == null) { p1ShipRef = this; this.ourController = ControllerInputManager.P1Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p1Inputs; } //If there's already a static reference for the p1 ship and not one for the p2 ship else if (p2ShipRef == null) { this.playerController = Players.P2; p2ShipRef = this; this.ourController = ControllerInputManager.P2Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p2Inputs; } //If there are already static references to both ships, we disable this object { this.gameObject.SetActive(false); } break; case Players.P2: //Making sure there's not already a static reference to the p2 ship if (p2ShipRef == null) { p2ShipRef = this; this.ourController = ControllerInputManager.P2Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p2Inputs; } //If there's already a static reference for the p2 ship, we disable this object else { this.gameObject.SetActive(false); } break; default: //Making sure there's not already a static reference to the p1 ship if (p1ShipRef == null) { p1ShipRef = this; this.ourController = ControllerInputManager.P1Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p1Inputs; } //If there's already a static reference for the p1 ship and not one for the p2 ship else if (p2ShipRef == null) { this.playerController = Players.P2; p2ShipRef = this; this.ourController = ControllerInputManager.P2Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p2Inputs; } //If there are already static references to both ships, we disable this object { this.gameObject.SetActive(false); } break; } //Passing our controller input to our movement mechanic scripts this.ourFreeMovement.ourShip = this; this.ourRailMovement.ourShip = this; //Getting our health and armor component reference this.ourHealth = this.GetComponent <HealthAndArmor>(); //Getting our energy component reference this.ourEnergy = this.GetComponent <ShipEnergy>(); //Looping through all of our weapons, wings and engines to tell them what player ID we are if (this.playerController == Players.P1) { this.mainWeapon.objectIDType = AttackerID.Player1; this.secondaryWeapon.objectIDType = AttackerID.Player1; this.shipCockpit.objectIDType = AttackerID.Player1; } else { this.mainWeapon.objectIDType = AttackerID.Player2; this.secondaryWeapon.objectIDType = AttackerID.Player2; this.shipCockpit.objectIDType = AttackerID.Player2; } foreach (ShipWingLogic wing in this.shipWings) { if (this.playerController == Players.P1) { wing.objectIDType = AttackerID.Player1; } else if (this.playerController == Players.P2) { wing.objectIDType = AttackerID.Player2; } } foreach (ShipEngineLogic engine in this.shipEngines) { if (this.playerController == Players.P1) { engine.objectIDType = AttackerID.Player1; } else if (this.playerController == Players.P2) { engine.objectIDType = AttackerID.Player2; } } //Getting the default pitch for the engine sound effect this.defaultPitch = this.engineSoundEmitter.ownerAudio.pitch; }