void Start() { CableTarget = transform; levelStart = FindObjectOfType <LevelStart>(); DayNightCycle = FindObjectOfType <DayNightCycle>(); rb = GetComponent <Rigidbody2D>(); playerSpawnPos = transform.position; deathController = GetComponent <PlayerDeathController>(); spriteRendered = anim.gameObject.GetComponent <SpriteRenderer>(); if (spriteRendered.gameObject.transform.GetChild(0)) { CableTarget = spriteRendered.gameObject.transform.GetChild(0); } CableNextDistance = CableMinDistance; CableLineRendered.SetPosition(0, playerSpawnPos); if (hasCable) { CableLineRendered.SetPosition(1, CableTarget.position); } CanEatLastCablePosition = false; }
void Update() { PlayerDeathController pdc = GetComponent <PlayerDeathController> (); //If this player is alive, then process movement if (pdc.isAlive()) { AnimatorStateInfo currentBaseState = anim.GetCurrentAnimatorStateInfo(0); if (currentBaseState.IsName("Base Layer.standing_aim_recoil") || currentBaseState.IsName("Base Layer.standing_draw_arrow")) { return; } if (currentType.Equals(ON_ICE)) { IceMovement(); } if (currentType.Equals(ON_GROUND)) { //The movement vector dependent on input. add in some speed GroundMovement(); } } }
//Method to initialize the coins/lives for the level, depending on the saved player stat persistence void InitializePlayerComponents() { //Find the necessary player controllers p1DC = GameObject.Find("PlayerOne_Green").GetComponent <PlayerDeathController> (); p2DC = GameObject.Find("PlayerTwo_Blue").GetComponent <PlayerDeathController> (); p1IC = GameObject.Find("PlayerOne_Green").GetComponent <PlayerItemsControllerMain> (); p2IC = GameObject.Find("PlayerTwo_Blue").GetComponent <PlayerItemsControllerMain> (); //If it is the first level if (SceneManager.GetActiveScene().name.Equals(scenes [0])) { //Set the players' lives to two each p1DC.SetLives(2); p2DC.SetLives(2); //Dont start with any coins p1IC.SetCurrencyCount(0); p1IC.SetCurrencyCount(0); } //Not first level, so load saved player stats else { //Set the lives/coins based on prev. level accumulated p1DC.SetLives(PlayerPrefs.GetInt(playerOneLivesKey)); p2DC.SetLives(PlayerPrefs.GetInt(playerTwoLivesKey)); p1IC.SetCurrencyCount(PlayerPrefs.GetInt(playerOneItemsKey)); p2IC.SetCurrencyCount(PlayerPrefs.GetInt(playerTwoItemsKey)); } }
void Update() { PlayerDeathController pdc = GetComponent <PlayerDeathController> (); //If the player is alive if (pdc.isAlive()) { //If the cool down for the bullet is still inactive if (GetCurrentCoolDown() < coolDown) { //Update the bullet skill slider cooldown UI skillSlider.value = GetCurrentCoolDown(); Fill.color = Color.Lerp(MinCoolDown, MaxCoolDown, GetCurrentCoolDown() / coolDown); } //Bullet skill ready, update the relevant UI component else { skillButton.interactable = true; } //The player has pressed the bullet fire control if (Input.GetKeyDown(KeyCode.RightControl)) { //If skill is able to be used if (SkillAvailable()) { SkillActivated(); } } } }
// Start is called before the first frame update void Start() { playerDead = false; playerRigidbody = GetComponent <Rigidbody2D>(); legsAnimator = GetComponentInChildren <Animator>(); playerSword = transform.Find("PlayerBlade").gameObject; ammoScript = GameObject.Find("Ammo Message").GetComponent <Ammo>(); levelEndScript = GameObject.Find("Cart (Level End Trigger)").GetComponent <LevelEnd>(); gameMaster = GameObject.FindGameObjectWithTag("GM").GetComponent <GameMaster>(); playerDeathControllerScript = gameObject.GetComponent <PlayerDeathController>(); //spawn the player at the checkpoint position gameObject.transform.position = gameMaster.lastCheckPointPosition; //get the player state when the level loads UpdatePlayerState(); }
void OnTriggerEnter(Collider other) { if (other.gameObject.CompareTag("Player")) { PlayerDeathController pdc = other.GetComponent <PlayerDeathController> (); pdc.HitByZombie(); } if (other.gameObject.CompareTag("BarrierLevel1") || other.gameObject.CompareTag("BarrierLevel2")) { SlideToSurviveAchievements.archerAchievement.FireBallBlocked(); gameObject.SetActive(false); } if (other.gameObject.CompareTag("IceZoneWall") || other.gameObject.CompareTag("Door") || other.gameObject.CompareTag("Boundary") || other.gameObject.CompareTag("LevelFinishBoundary")) { gameObject.SetActive(false); } }
//Upon collision with a zombie void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.CompareTag("BasicZombie")) { //If the player is not immune (when recently hit) and is alive if (!gameObject.tag.Equals("Immune") && alive) { //Invoke the necessary function HitByZombie(); } } //If the player has hit a player tomb, i,e the dead player if (hit.gameObject.CompareTag("PlayerTomb")) { //Remove the tomb gameobject hit.gameObject.SetActive(false); PlayerDeathController pdc = hit.transform.GetComponentInParent <PlayerDeathController> (); PlayerControllerMain pcm = hit.transform.GetComponentInParent <PlayerControllerMain> (); //If it was player one that was the dead player if (pcm.GetPlayerId() == 1) { GameObject playerOne = GameObject.Find("PlayerOne_Green"); //activate the player's rendering meshes again playerOne.transform.GetChild(2).gameObject.SetActive(true); } //If it was player two that was the dead player, do likewise if (pcm.GetPlayerId() == 2) { GameObject playerTwo = GameObject.Find("PlayerTwo_Blue"); playerTwo.transform.GetChild(2).gameObject.SetActive(true); } //set it to alive pdc.ToggleAlive(); //Has one life pdc.SetLives(1); } }
// Update is called once per frame void Update() { PlayerDeathController pdc = GetComponent <PlayerDeathController> (); //If the player is alive if (pdc.isAlive()) { //If the player has enough currency, and the appropriate button pressed if ((currencyCount >= freezeCost) && Input.GetKeyDown(KeyCode.Alpha2)) { //Freeze ability activated from player two FreezeAbilityActivated(2); } //If the player has enough currency, and the appropriate button pressed if ((currencyCount >= barrierCost) && Input.GetKeyDown(KeyCode.Alpha3)) { //Barrier ability activated from player two BarrierAbilityActivated(2); } } }
/// <summary> /// Start is called on the frame when a script is enabled just before /// any of the Update methods is called the first time. /// </summary> void Start() { _currentCollectionTime = collectionTime; _playerDeathController = GetComponentInParent <PlayerDeathController>(); }
void Start() { Debug.Log("Setting instance"); Instance = this; }