// Update is called once per frame void Update() { //Safety in case the player ship connection is lost -Adam if(mPlayer == null) { mPlayer = FindObjectOfType<PlayerShipController>(); } else { if( (!mPlayerTwoUI && mPlayer != null && mPlayer.mThreeBullet) || (mPlayerTwoUI && mPlayerTwo != null && mPlayerTwo.mThreeBullet) ) { //Make the bar move up and down mPowerTimerBar.enabled = true; if(!mPlayerTwoUI && mPlayer != null) { mPowerTimerBar.GetComponent<RectTransform>().localScale = new Vector3(1f, mPlayer.mThreeBulletTimer/30f, 1f); } else if(mPlayerTwoUI && mPlayerTwo != null) { mPowerTimerBar.GetComponent<RectTransform>().localScale = new Vector3(1f, mPlayerTwo.mThreeBulletTimer/30f, 1f); } mPowerTimerSwirl.transform.position = new Vector3(mPowerTimerSwirl.transform.position.x, swirlStartY + (mPowerTimerBar.GetComponent<RectTransform>().localScale.y * 24), mPowerTimerSwirl.transform.position.z); mPowerTimerBulb.enabled = true; } else { mPowerTimerBar.enabled = false; mPowerTimerBulb.enabled = false; } } }
// Use this for initialization private void Start() { //Finding our player ship reference switch (this.playerToTrack) { case Players.P1: this.ourShip = PlayerShipController.p1ShipRef; break; case Players.P2: this.ourShip = PlayerShipController.p2ShipRef; break; default: this.ourShip = PlayerShipController.p1ShipRef; break; } //If our ship reference is null, we disable this component if (this.ourShip == null) { this.enabled = false; } //Getting our camera component reference this.ourCamera = this.GetComponent <Camera>(); }
// Update is called once per frame void Update() { //Safety in case the player ship connection is lost -Adam if(mPlayer == null) { mPlayer = FindObjectOfType<PlayerShipController>(); } else if(mOverHeatBar.canvas.isActiveAndEnabled) //Only do stuff when the canvas is actually turned on { //Make the bar move up and down mOverHeatBar.GetComponent<RectTransform>().localScale = new Vector3(mPlayer.heatLevel/mPlayer.maxHeatLevel, 1, 1f); //Display overlay when overheated if(mPlayer.isOverheated) { mOverHeatOverlay.enabled = true; } else { mOverHeatOverlay.enabled = false; } } }
// Use this for initialization private void Start() { //Getting our weapon reference this.ourWeapon = this.GetComponent <Weapon>(); //If we always target player 1, we set our target to the player 1 ship if (this.targetType == EnemyTarget.Player1) { this.targetPlayer = PlayerShipController.p1ShipRef; } //If we always target player 2, we set our target to the player 2 ship else if (this.targetType == EnemyTarget.Player2) { //If the player 2 ship exists, we target it if (PlayerShipController.p2ShipRef != null) { this.targetPlayer = PlayerShipController.p2ShipRef; } //If the player 2 ship doesn't exist, we disable this object else { this.gameObject.SetActive(false); } } }
// Update is called once per frame void Update() { //Safety in case the player ship connection is lost -Adam if(mPlayer == null) { mPlayer = FindObjectOfType<PlayerShipController>(); } else if(mPowerTimerBar.canvas.isActiveAndEnabled) //Only do stuff when the canvas is actually turned on { //Make the bar move up and down ~Adam if(mPlayer.mThreeBullet) { //Make the bar move up and down mPowerTimerBar.enabled = true; mPowerTimerBar.GetComponent<RectTransform>().localScale = new Vector3(mPlayer.mThreeBulletTimer/30f, 1, 1f); } //Hide the bar when not powered up ~Adam else { mPowerTimerBar.enabled = false; } } }
// Update is called once per frame void FixedUpdate() { PlayerShipController ship = spaceManager.activeShip; MoveCamera(ship.transform); SetCameraZoom(ship); }
protected override void Initialize() { rigidbody = GetComponent <Rigidbody2D> (); PlayerShipController Player = FindObjectOfType <PlayerShipController> (); PlayerBody = Player.gameObject.GetComponent <Rigidbody2D> (); movementController.Moved += ctlr_Moved; }
// Use this for initialization void Start() { //get the face sprite to change mFace = GetComponent<Image>(); //find the palyer and the score manager ~Adam mPlayer1Ship = FindObjectOfType<PlayerShipController>(); mScoreMan = FindObjectOfType<ScoreManager>(); }
// Use this for initialization void Start() { //Find the player ship -Adam mPlayer = FindObjectOfType<PlayerShipController>(); //Find the second player's ship ~Adam if(mPlayerTwoUI && mPlayer.mPlayerTwo != null) { mPlayerTwo = mPlayer.mPlayerTwo; } }
private void Start() { playerShipController = GameObject.FindGameObjectWithTag("PlayerShip").GetComponent <PlayerShipController>(); enemies = Resources.LoadAll <GameObject>("Enemies"); asteroids = Resources.LoadAll <GameObject>("Asteroids/Prefabs"); powerups = Resources.LoadAll <GameObject>("PowerUp/Prefabs/PowerupsShooter"); timeToStartNextWave = Time.time + waveStart; timetoSendPowerUp = timeToStartNextWave * 1; formations = GetComponent <FormationConstructor>(); }
void SetCameraZoom(PlayerShipController ship) { float lerpDist = ship.savedVelocity / ship.maxLinearVelocity; float targetCameraSize = Mathf.Lerp(ship.minCameraSize, ship.maxCameraSize, lerpDist); float distToTargetCameraSize = Mathf.Abs(camera.orthographicSize - targetCameraSize); if (distToTargetCameraSize > 0.01f) { camera.orthographicSize = Mathf.Lerp(camera.orthographicSize, targetCameraSize, zoomSpeed * Time.deltaTime); } }
// Use this for initialization private void Start() { //Getting our player ship reference this.ourShip = this.GetComponent <PlayerShipController>(); //Making sure our roll trail object is disabled if (this.rollTrails != null) { this.rollTrails.SetActive(false); } }
public static void HandleCollision(this ICollidable me, ICollidable target) { // Reference frame: target is standing still (this makes calculations easier) // Adjust velocities to fit the reference frame Vector3 otherInitialVelocity = target.GetVelocity(); Vector3 initialVelocity = me.GetVelocity() - otherInitialVelocity; // Target will be sent directly away from my center of mass Vector3 directionTowardsOther = (target.GetPosition() - me.GetPosition()).normalized; // Get my initial kinetic energy // My KE is equal to the total KE of the system, because the target is stationary in this reference frame float initialKineticEnergy = (0.5f * me.GetMass() * me.GetVelocity().sqrMagnitude); // How much KE is transferred to the target depends on how direct the hit was float kEPercentage = Vector3.Dot(directionTowardsOther, initialVelocity.normalized); float transferredKE = initialKineticEnergy * kEPercentage; // Elasticity determines how much KE is converted into damage and how much becomes recoil float elasticityAvg = (me.GetElasticity() + target.GetElasticity()) / 2f; float recoilKE = transferredKE * elasticityAvg; float convertedKE = transferredKE - recoilKE; // Get the new speed of the target from the recoil KE and set velocity in the direction of impact float theirSpeed = Mathf.Sqrt(Mathf.Abs(2f * recoilKE * kEPercentage) / me.GetMass()); Vector3 theirNewVelocity = directionTowardsOther * theirSpeed; // Calculate my new velocity using the conservation of momentum formula Vector3 myNewVelocity = initialVelocity - ((target.GetMass() * theirNewVelocity) / me.GetMass()); // Set velocities of both bodies, shifting back to the global reference frame me.SetVelocity(myNewVelocity + otherInitialVelocity); target.SetVelocity(theirNewVelocity + otherInitialVelocity); // Take damage based on the converted KE me.TakeDamage(me.CalculateCollisionDamageReduction(target.GetDamage(convertedKE)), false, VectorHelper.Midpoint(me.GetPosition(), target.GetPosition())); target.TakeDamage(target.CalculateCollisionDamageReduction(me.GetDamage(convertedKE)), false, VectorHelper.Midpoint(me.GetPosition(), target.GetPosition())); // Move to positions so the colliders aren't inside each other float totalMaxRadius = me.GetCollisionRadius() + target.GetCollisionRadius(); float actualMaxRadius = (target.GetPosition() - me.GetPosition()).magnitude; float radiusDifference = totalMaxRadius - actualMaxRadius; float myRadiusPercentage = me.GetCollisionRadius() / totalMaxRadius; Vector3 weightedMidpoint = me.GetPosition() + directionTowardsOther * actualMaxRadius * myRadiusPercentage; target.SetPosition(weightedMidpoint + directionTowardsOther * target.GetCollisionRadius()); me.SetPosition(weightedMidpoint - directionTowardsOther * me.GetCollisionRadius()); // Communicate collision to parent spawner if other is player ship try { ISpawnable spawnable = (me as MonoBehaviour).GetComponent <ISpawnable>(); PlayerShipController playerShip = (target as MonoBehaviour).GetComponent <PlayerShipController>(); if (spawnable != null && playerShip != null) { spawnable.GetParent().SavePlayerCollision(playerShip.transform.position); } } catch (System.Exception e) { Debug.LogWarningFormat("Using ICollidable that isn't a MonoBehaviour! How?/nInner Exception: '{0}'", e.Message); } }
// Use this for initialization void Start() { swirlStartY = mPowerTimerSwirl.transform.position.y; //Find the player ship -Adam mPlayer = FindObjectOfType<PlayerShipController>(); //Find the second player's ship ~Adam if(mPlayerTwoUI && mPlayer.mPlayerTwo != null) { mPlayerTwo = mPlayer.mPlayerTwo; } }
private void ExitWind() { foreach (Rigidbody2D rigidbody in objectsUnderWind.Keys) { rigidbody.AddForce(-(objectsUnderWind[rigidbody] * (currentWindSpeed * 20))); PlayerShipController player = rigidbody.GetComponent <PlayerShipController>(); if (player != null) { player.SetUnderWind(false); } } objectsUnderWind.Clear(); }
// Update is called once per frame void Update() { //Make sure we always have a ScoreManager ~Adam if(mScoreManager == null) { mScoreManager = FindObjectOfType<ScoreManager>() as ScoreManager; } //Make sure we always have a Ship ~Adam if(mPlayerAvatar == null) { mPlayerAvatar = FindObjectOfType<PlayerShipController>() as PlayerShipController; } }
public void initJumper(StarSystem starSystem) { this.starSystem = starSystem; base.init(); jumpBG = GameObject.Find("Jump Background").GetComponent <SpriteRenderer>(); jumpBG.gameObject.SetActive(false); jumpBG.enabled = true; bgTrans = jumpBG.transform; style = messageStyle; cameraController = Camera.main.GetComponent <CameraController>(); cameraTrans = cameraController.transform; playerController = GetComponent <PlayerShipController>(); }
private void AllowMovement(PlayerShipController playerShipController, bool isAllowed) // установление правил движения игрока при контакте со стеной { if (playerShipController != null) { if (_isRightWall) { playerShipController.SetPossibleRightMove(isAllowed); } else { playerShipController.SetPossibleLeftMove(isAllowed); } } }
void OnActiveShipChange(PlayerShipController newActiveShip) { foreach (PlayerShipController ship in playerShips) { if (ship == newActiveShip) { _activeShip = newActiveShip; _activeShip.enabled = true; } else { ship.enabled = false; } } }
// Use this for initialization void Start() { //Find the score manager and the player ships ~Adam if(FindObjectOfType<ScoreManager>() != null) { mScoreMan = FindObjectOfType<ScoreManager>(); } if(FindObjectOfType<PlayerShipController>() != null) { mP1Ship = FindObjectOfType<PlayerShipController>(); } if(FindObjectOfType<PlayerTwoShipController>() != null) { mP2Ship = FindObjectOfType<PlayerTwoShipController>(); } }
public void Interact(PlayerShipController player) { Debug.Log("Oh no you friccin moron, you just got INTERACTED! Tag your friend to totally INTERACT them."); InteractionUI window = GameObject.Instantiate(Resources.Load("Prefabs/UI/InteractionWindow") as GameObject).GetComponent <InteractionUI>(); window.transform.SetParent(GameObject.Find("ScreenUI").transform, false); window.player = player; window.source = this; RectTransform t = (RectTransform)window.transform; t.offsetMax = Vector2.zero; foreach (OrbitalInteraction i in interactions) { window.AddTab(i); } }
// Use this for initialization void Start() { mPlayer = FindObjectOfType<PlayerShipController>(); if(mPlayer != null) { mPlayer.mShipStolen = true; } //Randomly decide the direction the ship will move upon being released mMovingRight = (Random.value < 0.5); //Base the movement speed off of the players movement speed mMovementSpeed = mPlayer.mMovementSpeed; //Like the player, the later the level, the faster the captured ship shoots. //mShootTimerDefault = 0.25f-(0.15f/25f*Application.loadedLevel); mShootTimerDefault = 5f; mShootTimer = mShootTimerDefault; if(FindObjectOfType<PlayerTwoShipController>()!= null) { Destroy (this.gameObject); } }
public override void ApplyEffectOnPlayer(PlayerShipController player) { player.GetComponent <Spaceship>().AddHealth(healthBonus); base.ApplyEffectOnPlayer(); }
// Use this for initialization private void Start() { //Getting our ship component reference this.ourShip = this.GetComponent <PlayerShipController>(); }
void Start() { playerShipController = playerShip.GetComponent <PlayerShipController>(); }
// Update is called once per frame void Update() { if(mPlayer == null) { mPlayer = FindObjectOfType<PlayerShipController>(); if(mPlayer != null) { mPlayer.mShipStolen = true; } } //Being towed away by the grabbing enemy if(mGrabbingEnemy != null && mInTow == true) { transform.position = mGrabbingEnemy.mTowPoint.position; foreach (ParticleSystem shipTrail in GetComponentsInChildren<ParticleSystem>()) { shipTrail.enableEmission = false; } } //Moving left and right once no longer being towed else { if (transform.position.z != -2) { transform.position = new Vector3(transform.position.x, transform.position.y, -2); } foreach (ParticleSystem shipTrail in GetComponentsInChildren<ParticleSystem>()) { shipTrail.enableEmission = true; } //Staying within the bounds of the play space if (transform.position.x >= 19f) { mMovingRight = false; } else if (transform.position.x <= -19f) { mMovingRight = true; } if(transform.position.y < -30f) { transform.position = new Vector3(transform.position.x, -30f, transform.position.z); } if (transform.position.y > 23f) { transform.position = new Vector3(transform.position.x, 23, transform.position.z); } if(mMovingRight) { transform.position += Vector3.right*mMovementSpeed* Time.deltaTime; } else { transform.position += Vector3.right*mMovementSpeed*-1f* Time.deltaTime; } } //Shooting back at the player mShootTimer -= Time.deltaTime; //Instantiate an enemy bullet if the player is below this enemy if(Mathf.Abs(mPlayer.transform.position.x - transform.position.x) <= 2f && mShootTimer <=0f && mCapturedShipBullet != null) { GameObject enemyBullet; enemyBullet = Instantiate(mCapturedShipBullet, transform.position, Quaternion.identity) as GameObject; mShootTimer = mShootTimerDefault; } }
public virtual void ApplyEffectOnPlayer(PlayerShipController player = null) { Destroy(this.gameObject); }
private void Awake() { S = this; rigid = GetComponent <Rigidbody>(); }
// Update is called once per frame void Update() { //make sure the player and the score manager aren't null if(mPlayer1Ship == null) { mPlayer1Ship = FindObjectOfType<PlayerShipController>(); } if(mScoreMan == null) { mScoreMan = FindObjectOfType<ScoreManager>(); } //Change the face if(mPlayer1Ship != null && mScoreMan != null) { //Firing super weapon ~Adam if(mPlayer1Ship.mBigBlast.activeInHierarchy || mPlayer1Ship.mLaserFist.activeInHierarchy) { mFace.sprite = mEmotes[8]; } //Getting Hit else if(mScoreMan.mPlayerSafeTime > 0f) { mFace.sprite = mEmotes[7]; } //OverHeated else if(mPlayer1Ship.isOverheated) { mFace.sprite = mEmotes[6]; } //Shielded else if(mPlayer1Ship.mShielded) { mFace.sprite = mEmotes[5]; } //Dead else if(mScoreMan.mLivesRemaining <= 0) { mFace.sprite = mEmotes[0]; } //1-25% else if(mScoreMan.mLivesRemaining/(mScoreMan.mMaxLives+0.00001f) <= 0.25f) { mFace.sprite = mEmotes[1]; } //26-50% else if(mScoreMan.mLivesRemaining/(mScoreMan.mMaxLives+0.00001f) <= 0.5f) { mFace.sprite = mEmotes[2]; } //50-75% else if(mScoreMan.mLivesRemaining/(mScoreMan.mMaxLives+0.00001f) <= 0.75f) { mFace.sprite = mEmotes[3]; } //76-100% else { mFace.sprite = mEmotes[4]; } } else if(mScoreMan != null && mScoreMan.mLivesRemaining <= 0) { mFace.sprite = mEmotes[0]; } }
// Update is called once per frame private void Update() { //If our target type focuses on the closest enemy, we find the closest if (this.targetType == EnemyTarget.Closest) { //If the player 2 ship doesn't exist, we go with player 1 by default if (PlayerShipController.p2ShipRef == null) { this.targetPlayer = PlayerShipController.p1ShipRef; } //Otherwise we actually have to find the closest else { //Floats to hold the distances to each ship float p1Dist = Vector3.Distance(this.transform.position, PlayerShipController.p1ShipRef.transform.position); float p2Dist = Vector3.Distance(this.transform.position, PlayerShipController.p2ShipRef.transform.position); //If the player 1 distance is closer, we use that ship if (p1Dist < p2Dist) { this.targetPlayer = PlayerShipController.p1ShipRef; } //If the player 2 distance is closer, we use that ship else { this.targetPlayer = PlayerShipController.p2ShipRef; } } } //If the target player isn't in the attack range, nothing happens if (Vector3.Distance(this.transform.position, this.targetPlayer.transform.position) > this.attackRange) { return; } //Variable to hold the offset of the player position to target Vector3 posToShoot = this.LeadShipPosition(); //Looping through all of our rotation objects so they face our target player foreach (ObjToRotate objR in this.rotationObjects) { //If we rotate all of the axis, then we can rotate using quaternions if (objR.rotateX && objR.rotateY && objR.rotateZ) { //Getting the quaternion rotation to face the player position Quaternion newRot = Quaternion.LookRotation(posToShoot - objR.objToRotate.position); //Rotating to face the new rotation given our rotation speed objR.objToRotate.rotation = Quaternion.Lerp(objR.objToRotate.rotation, newRot, objR.rotationSpeed); } //Otherwise, we rotate for each designated axis else { //If we rotate the X axis if (objR.rotateX) { //Getting the quaternion rotation to only move the X rotation to face the player position Vector3 xLookPos = new Vector3(posToShoot.x - objR.objToRotate.position.x, posToShoot.y - objR.objToRotate.position.y, posToShoot.z - objR.objToRotate.position.z); Quaternion newXRot = Quaternion.LookRotation(xLookPos); //Rotating the X direction to face the new rotation given our speed objR.objToRotate.rotation = Quaternion.Lerp(objR.objToRotate.rotation, newXRot, objR.rotationSpeed); //If this object ONLY rotates the X value, we clamp the YZ rotations if (objR.rotateX && !objR.rotateY && !objR.rotateZ) { objR.objToRotate.localEulerAngles = new Vector3(objR.objToRotate.localEulerAngles.x, 0, 0); } } //If we rotate the Y axis if (objR.rotateY) { //Getting the quaternion rotation to only move the Y rotation to face the player position Vector3 yLookPos = new Vector3(posToShoot.x - objR.objToRotate.position.x, posToShoot.y - objR.objToRotate.position.y, posToShoot.z - objR.objToRotate.position.z); Quaternion newYRot = Quaternion.LookRotation(yLookPos); //Rotating the Y direction to face the new rotation given our speed objR.objToRotate.rotation = Quaternion.Lerp(objR.objToRotate.rotation, newYRot, objR.rotationSpeed); //If this object ONLY rotates the Y value, we clamp the XZ rotations if (!objR.rotateX && objR.rotateY && !objR.rotateZ) { objR.objToRotate.localEulerAngles = new Vector3(0, objR.objToRotate.localEulerAngles.y, 0); } } //If we rotate the Z axis if (objR.rotateZ) { //Getting the quaternion rotation to only move the Z rotation to face the player position Vector3 zLookPos = new Vector3(posToShoot.x - objR.objToRotate.position.x, posToShoot.y - objR.objToRotate.position.y, posToShoot.z - objR.objToRotate.position.z); Quaternion newZRot = Quaternion.LookRotation(zLookPos); //Rotating the X direction to face the new rotation given our speed objR.objToRotate.rotation = Quaternion.Lerp(objR.objToRotate.rotation, newZRot, objR.rotationSpeed); //If this object ONLY rotates the Z value, we clamp the XY rotations if (!objR.rotateX && !objR.rotateY && objR.rotateZ) { objR.objToRotate.localEulerAngles = new Vector3(0, 0, objR.objToRotate.localEulerAngles.z); } } } } //Counting down our cooldown times if they exist if (this.currentCooldown > 0) { this.currentCooldown -= Time.deltaTime; //If our cooldown between firing is up, we reload our current clip this.currentClipSize = this.clipSize; } if (this.currentTimeBetweenShots > 0) { this.currentTimeBetweenShots -= Time.deltaTime; } //Firing at the player whenever possible if (this.currentCooldown <= 0) { //If our time between shots is up, we can fire if (this.currentTimeBetweenShots <= 0) { //Firing our weapon this.ourWeapon.FireWeapon(true, false, false); //Reducing the number of shots in our clip this.currentClipSize -= 1; //If our clip is empty, we start our cooldown if (this.currentClipSize < 1) { this.currentCooldown = this.cooldownAfterClip; } //Otherwise we start our cooldown between shots else { this.currentTimeBetweenShots = this.timeBetweenShots; } } } }
// Use this for initialization void Start() { //Find the player ship -Adam mPlayer = FindObjectOfType<PlayerShipController>(); }
// Update is called once per frame void Update() { if(mSteamUp == null) { mSteamUp = GameObject.Find(mSteamUpName).GetComponent<ParticleSystem>(); } else { if(mPlayer.heatLevel/mPlayer.maxHeatLevel < 0.9f && !mSteamUp.GetComponent<AudioSource>().isPlaying) { mCanPlaySteamNoise = true; } } if(mSteamDown == null) { mSteamDown = GameObject.Find(mSteamDownName).GetComponent<ParticleSystem>(); } //Read Heat Level, Maximum Heat Level, and overheat status from either player 1 or player 2 ~Adam if(!mPlayerTwoUI && mPlayer != null) { mHeatLevel = mPlayer.heatLevel; mMaxHeat = mPlayer.maxHeatLevel; mIsOverheated = mPlayer.isOverheated; } else if (mPlayerTwoUI && mPlayerTwo != null) { mHeatLevel = mPlayerTwo.heatLevel; mMaxHeat = mPlayerTwo.maxHeatLevel; mIsOverheated = mPlayerTwo.isOverheated; } //Safety in case the player ship connection is lost -Adam if(mPlayer == null) { mPlayer = FindObjectOfType<PlayerShipController>(); } else if (mPlayerTwo == null && mPlayerTwoUI && mPlayer.mPlayerTwo != null) { mPlayerTwo = mPlayer.mPlayerTwo; } else if(GetComponent<Image>().canvas.isActiveAndEnabled) //Only do stuff when the canvas is actually turned on { //Make the bar move up and down mOverHeatBar.GetComponent<RectTransform>().localScale = new Vector3(1f, mHeatLevel/mMaxHeat, 1f); //Display overlay when overheated if(mIsOverheated) { mOverHeatOverlay.enabled = true; GetComponent<Animator>().speed = 0f; if(mSteamUp != null && mSteamDown != null) { mSteamUp.Play(); mSteamUp.GetComponentInChildren<ParticleSystem>().Play(); mSteamDown.Stop(); } mRedBulb.enabled = false; mBlankBulb.enabled = false; } else { if(mSteamUp != null & mSteamDown != null) { mSteamDown.Play(); mSteamUp.Stop(); mSteamUp.GetComponentInChildren<ParticleSystem>().Stop(); } mOverHeatOverlay.enabled = false; if(mHeatLevel/mMaxHeat > 0.9f) { mRedBulb.enabled = true; mBlankBulb.enabled = false; GetComponent<Animator>().speed = 5f; if(mSteamDown != null) { mSteamDown.startSpeed = 5f; mSteamDown.startLifetime = 0.5f; mSteamDown.emissionRate = 50f; if(mSteamUp != null && mCanPlaySteamNoise) { mSteamUp.GetComponent<AudioSource>().Play(); mCanPlaySteamNoise = false; } } } else { mRedBulb.enabled = false; mBlankBulb.enabled = true; GetComponent<Animator>().speed = 1f; if(mSteamDown != null) { mSteamDown.startSpeed = 1f; mSteamDown.startLifetime = 2f; mSteamDown.emissionRate = 10f; } } } } //Hide the steam if the canvas it turned off or the ship is missing else { if(mSteamUp != null & mSteamDown != null) { mSteamUp.Stop(); mSteamUp.GetComponentInChildren<ParticleSystem>().Stop(); mSteamDown.Stop(); } } }
//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; }
// Use this for initialization void Start() { mScoreManager = FindObjectOfType<ScoreManager>() as ScoreManager; mPlayerShip = FindObjectOfType<PlayerShipController>() as PlayerShipController; mScreenFader.GetComponent<Renderer>().material.color = new Color(0f,0f,0f,0f); }
// Use this for initialization void Start() { mScoreManager = FindObjectOfType<ScoreManager>() as ScoreManager; mPlayerAvatar = FindObjectOfType<PlayerShipController>() as PlayerShipController; }
//Function called from PlayerStartingPositin.Awake to set the player ship controller IDs public void SetPlayerShipID(Players playerID_) { //Setting this ship's controller to the given ID this.playerController = playerID_; //Getting our controller input based on which player this is switch (playerID_) { case Players.P1: this.gameObject.SetActive(true); p1ShipRef = this; this.ourController = ControllerInputManager.P1Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p1Inputs; this.GetComponent <CameraWeight>().playerThatCanFollow = Players.P1; this.ourRailMovement.railParentObj.GetComponent <CameraWeight>().playerThatCanFollow = Players.P1; this.GetComponent <CustomShipTextures>().SetPlayerShipID(Players.P1); this.shipShield.objectIDType = AttackerID.Player1; break; case Players.P2: this.gameObject.SetActive(true); p2ShipRef = this; this.ourController = ControllerInputManager.P2Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p2Inputs; this.GetComponent <CameraWeight>().playerThatCanFollow = Players.P2; this.ourRailMovement.railParentObj.GetComponent <CameraWeight>().playerThatCanFollow = Players.P2; this.GetComponent <CustomShipTextures>().SetPlayerShipID(Players.P2); this.shipShield.objectIDType = AttackerID.Player2; //If this ship was set as the p1 ship reference, we remove it if (p1ShipRef == this) { p1ShipRef = null; } break; default: this.gameObject.SetActive(true); p1ShipRef = this; this.ourController = ControllerInputManager.P1Controller; this.ourCustomInputs = CustomInputSettings.globalReference.p1Inputs; this.GetComponent <CameraWeight>().playerThatCanFollow = Players.P1; this.ourRailMovement.railParentObj.GetComponent <CameraWeight>().playerThatCanFollow = Players.P1; this.GetComponent <CustomShipTextures>().SetPlayerShipID(Players.P1); this.shipShield.objectIDType = AttackerID.Player1; break; } //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; } } }
// Use this for initialization private void Awake() { //If this starting position is for player 1 if (this.playerToSpawn == Players.P1) { //Spawning in the player 1 ship prefab at this transform position and rotation GameObject p1ShipObj = GameObject.Instantiate(GlobalData.globalReference.player1Ship.gameObject) as GameObject; p1ShipObj.transform.position = this.transform.position; p1ShipObj.transform.rotation = this.transform.rotation; //Getting the component for the player ship controller PlayerShipController p1Ship = p1ShipObj.GetComponent <PlayerShipController>(); p1Ship.SetPlayerShipID(Players.P1); //If the starting movement type is "Rail" we tell it which rail to start on if (this.movementType == RegionZone.RegionMovement.Rail) { p1Ship.ourRailMovement.enabled = true; p1Ship.ourFreeMovement.enabled = false; } //If the starting movement type is "Free" we enable the free movement component else if (this.movementType == RegionZone.RegionMovement.Free) { p1Ship.ourRailMovement.enabled = false; p1Ship.ourFreeMovement.enabled = true; } //Enabling the camera for this player this.cameraToActivate.rootPosObj.SetActive(true); //If the game mode is single player, we make sure the camera is full-screen if (GlobalData.globalReference.singlePlayerMode) { this.cameraToActivate.GetComponent <Camera>().rect = new Rect(0, 0, 1, 1); } //If the game mode is co-op, we make sure the camera takes up the top half of the screen else { this.cameraToActivate.GetComponent <Camera>().rect = new Rect(0, 0.5f, 1, 0.5f); } } //If this starting position is for player 2 and the game mode is co-op else if (this.playerToSpawn == Players.P2 && !GlobalData.globalReference.singlePlayerMode) { //Spawning in the player 2 ship prefab at this transform position and rotation GameObject p2ShipObj = GameObject.Instantiate(GlobalData.globalReference.player2Ship.gameObject) as GameObject; p2ShipObj.transform.position = this.transform.position; p2ShipObj.transform.rotation = this.transform.rotation; //Getting the component for the player ship controller PlayerShipController p2Ship = p2ShipObj.GetComponent <PlayerShipController>(); p2Ship.SetPlayerShipID(Players.P2); //If the starting movement type is "Rail" we tell it which rail to start on if (this.movementType == RegionZone.RegionMovement.Rail) { p2Ship.ourRailMovement.enabled = true; p2Ship.ourFreeMovement.enabled = false; } //If the starting movement type is "Free" we enable the free movement component else if (this.movementType == RegionZone.RegionMovement.Free) { p2Ship.ourRailMovement.enabled = false; p2Ship.ourFreeMovement.enabled = true; } //Enabling the camera for this player this.cameraToActivate.rootPosObj.SetActive(true); //Making sure the camera takes up the lower half of the screen this.cameraToActivate.GetComponent <Camera>().rect = new Rect(0, 0, 1, 0.5f); } }
public override void ApplyEffectOnPlayer(PlayerShipController player) { player.Dps = attackSpeedBonus; base.ApplyEffectOnPlayer(); }
// Update is called once per frame void Update() { if(mScoreMan != null) { mHealthValue = mScoreMan.mLivesRemaining/(mScoreMan.mMaxLives+.00001f); //Flash the ship parts ~Adam if(mScoreMan.mPlayerSafeTime >0f) { mShipHull.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipLeftWing.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipRightWing.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipLeftClaw.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipRightClaw.GetComponent<Animator>().SetInteger("UIFlashState", 1); } else { mShipHull.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipLeftWing.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipRightWing.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipLeftClaw.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipRightClaw.GetComponent<Animator>().SetInteger("UIFlashState", 0); } } if(mHealthValue<0.8f) { mShipRightClaw.GetComponent<Animator>().SetInteger("UIFlashState", 2); } if(mHealthValue<0.6f) { mShipLeftClaw.GetComponent<Animator>().SetInteger("UIFlashState", 2); } if(mHealthValue<0.4f) { mShipRightWing.GetComponent<Animator>().SetInteger("UIFlashState", 2); } if(mHealthValue<0.2f) { mShipLeftWing.GetComponent<Animator>().SetInteger("UIFlashState", 2); } if(mHealthValue < 0f) { mHealthValue = 0f; } if(!mP2UI && mP1Ship != null) { //Adjust the meters ~Adam mOverheatValue = mP1Ship.heatLevel/mP1Ship.maxHeatLevel; if(mOverheatValue < 0f) { mOverheatValue = 0f; } mTripleTimerValue = mP1Ship.mThreeBulletTimer/30f; if(mTripleTimerValue < 0f) { mTripleTimerValue = 0f; } //Flash the ship gun parts ~Adam if(mScoreMan != null) { if(mP1Ship.mThreeBullet) { if(mScoreMan.mPlayerSafeTime >0f) { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 1); } else { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 0); } } else { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 2); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 2); } } //Show this player's individual score ~Adam mScoreText.text = "P1 Score: " + mScoreMan.mP1Score; } else if(mP2UI && mP2Ship != null) { //Adjust the meters ~Adam mOverheatValue = mP2Ship.heatLevel/mP2Ship.maxHeatLevel; if(mOverheatValue < 0f) { mOverheatValue = 0f; } mTripleTimerValue = mP2Ship.mThreeBulletTimer/30f; if(mTripleTimerValue < 0f) { mTripleTimerValue = 0f; } //Flash the ship gun parts ~Adam if(mScoreMan != null) { if(mP2Ship.mThreeBullet) { if(mScoreMan.mPlayerSafeTime >0f) { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 1); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 1); } else { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 0); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 0); } } else { mShipLeftGun.GetComponent<Animator>().SetInteger("UIFlashState", 2); mShipRightGun.GetComponent<Animator>().SetInteger("UIFlashState", 2); } } //Show this player's individual score ~Adam mScoreText.text = "P2 Score: " + mScoreMan.mP2Score; } //Control the overheat whistle noise if(mOverheatValue < 0.9f && GetComponent<AudioSource>().isPlaying) { mCanPlaySteamNoise = true; } else if (mOverheatValue > 0.9f && mCanPlaySteamNoise) { GetComponent<AudioSource>().Play(); mCanPlaySteamNoise = false; } //Find ships if they're null else if (!mP2UI && mP1Ship == null) { if(FindObjectOfType<PlayerShipController>() != null) { mP1Ship = FindObjectOfType<PlayerShipController>(); } } else if (mP2UI && mP2Ship == null) { if(FindObjectOfType<PlayerTwoShipController>() != null) { mP2Ship = FindObjectOfType<PlayerTwoShipController>(); } } //Set the bar sizes ~Adam mHealthBar.rectTransform.localScale = new Vector3(mHealthValue, 1f,1f); mOverheatBar.rectTransform.localScale = new Vector3(mOverheatValue, 1f,1f); mTripleTimerBar.rectTransform.localScale = new Vector3(mTripleTimerValue, 1f,1f); }
public void Start() { //var ship = Resources.Load<GameObject>("ship1.prefab"); //var ship = Resources.Load<GameObject>("ShipGameStarterKit/Models/Ship of the Line/ship1.prefab"); var ship = Resources.Load <GameObject>("ship_1"); if (ship == null) { Debug.Log("没找到船只的预设"); } else { //ship.transform.position = new Vector3(0, 0, 0); //ship.transform.localScale = new Vector3(1, 1, 1); var ship1 = Object.Instantiate(ship) as GameObject; var pc = Instantiate(Resources.Load <GameObject>("PlayerCamera")) as GameObject; pc.transform.parent = ship1.transform; var so = pc.GetComponentsInChildren <ShipOrbit>()[0]; var shipController = new PlayerShipController(); so.control = shipController; shipController.BindU3DModel(ship1); ShipTemplate st = new ShipTemplate { Id = 1, Pref = "ship_1", Speed = 4, SpeededUpSec = 15, AnglePreSec = 10.3f, AngleUpSec = 5.0f, Hp = 1000 }; shipController.SetShipTemplate(st); PlayerShip = shipController; // 这里先模拟船只向前移动(z轴增加的移动) // 在Z轴上移动 PlayerShip.Direction = new Vector3(0, 0, 1); ShipManager.Instatnce.AddShip(PlayerShip); var ship2 = Object.Instantiate(Resources.Load <GameObject>("ship_2")) as GameObject; //ship2.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f); ship2.transform.position = new Vector3(40, 0, 0); npcShip1 = new NpcShipController(); npcShip1.BindU3DModel(ship2); npcShip1.SetShipTemplate(st); ShipManager.Instatnce.AddShip(npcShip1); var ship3 = Object.Instantiate(Resources.Load <GameObject>("ship_3")) as GameObject; ship3.transform.position = new Vector3(-40, 0, 0); var camera = GameObject.Find("Main Camera"); camera.AddComponent <FrmPlayerShip>(); } lastUpdateTime = OneServer.NowTime; }
private void Start() { playing = false; if (gameMaster != null) { playerNumber = gameMaster.AddPlayer(gameObject); gameMasterActive = true; } else if (isLocalPlayer && isServer) { NetworkServer.SpawnWithClientAuthority(Instantiate(gameMasterPrefab, Vector3.zero, Quaternion.identity), connectionToClient); } //Debug.Log(0); ResetHealth(); if (isLocalPlayer) { // Generate a name for the player CmdSetPlayerName(namePool[Random.Range(0, namePool.Length)] + "_" + Random.Range(0, 99)); GlobalVars.globalGameObjects.TryGetValue("hud", out hud); healthUI = hud.transform.Find("Health UI").GetComponent <Text>(); //Debug.Log(1); } if (isLocalPlayer && isServer) { //Debug.Log(2); icebergMaster = Instantiate(icebergMasterPrefab, Vector3.zero, Quaternion.identity); NetworkServer.SpawnWithClientAuthority(icebergMaster, connectionToClient); //GameObject.Find("Multiplayer_Manager").GetComponent<NetworkManager>().customConfig = true; //GameObject.Find("Multiplayer_Manager").GetComponent<NetworkManager>().connectionConfig.MaxCombinedReliableMessageSize = 248; //GameObject.Find("Multiplayer_Manager").GetComponent<NetworkManager>().connectionConfig.MaxCombinedReliableMessageCount = 248; //GameObject.Find("Multiplayer_Manager").GetComponent<NetworkManager>().connectionConfig.MaxSentMessageQueueSize = 248; //setting cache here if (globalGameObjects.TryGetValue("multiplayer_manager", out gameObjectCache)) { gameObjectCache.GetComponent <NetworkManager>().customConfig = true; gameObjectCache.GetComponent <NetworkManager>().connectionConfig.MaxCombinedReliableMessageSize = 248; gameObjectCache.GetComponent <NetworkManager>().connectionConfig.MaxCombinedReliableMessageCount = 248; gameObjectCache.GetComponent <NetworkManager>().connectionConfig.MaxSentMessageQueueSize = 248; } else { Debug.LogError("Could not find Multiplayer Manager"); } //NetworkServer.Configure(Network.ConnectionConfig) } //Debug.Log(3); kaijuCore = playerObjects[0].GetComponent <KaijuCore>(); shipCore = playerObjects[1].GetComponent <ShipCore>(); shipTurret = playerObjects[1].transform.Find("Ship Pivot/Ship Body/Turret Base/Turret Horizontal").GetComponent <ShipTurret>(); kaijuController = playerObjects[0].GetComponent <PlayerKaijuController>(); shipController = playerObjects[1].GetComponent <PlayerShipController>(); Debug.Log(playerObjects[1]); Debug.Log(shipController); //Debug.Log(4); isKaiju = false; globalGameObjects.TryGetValue("kaiju_tracker", out kaijuTracker); if (isLocalPlayer) { GlobalVars.globalGameObjects.TryGetValue("starting_camera", out startingCamera); GlobalVars.globalGameObjects.TryGetValue("ocean", out ocean); } }