void Update() { if (newCharacter) { followTarget = characterSelector.GetCharacterObject(); } if (characterSelector != null) { if (characterSelector.GetCharacterActive()) //checks if the character is active { targetPos = new Vector3(followTarget.transform.position.x, followTarget.transform.position.y, transform.position.z); //using the z position of the camera } else { if (playerStartPoint != null) { targetPos = new Vector3(playerStartPoint.GetStartPosition().x, playerStartPoint.GetStartPosition().y, -10); //sets the camera's default position to the position of the player start point game object to prevent camera drag on character spawn } else { targetPos = new Vector3(0, 0, -10); //if there is no player start point present, default the camera to these values } } } transform.position = Vector3.Lerp(transform.position, targetPos, moveSpeed * Time.deltaTime); //current position, new position (target position), amount of movement per frame - Using Time.deltaTime to adjust to computer framerates }
IEnumerator DashTimer() { BoxCollider2D[] playerColliders = characterSelector.GetCharacterObject().GetComponentsInChildren <BoxCollider2D>(); Vector2 storeSwordColliderSize = new Vector2(); dashing = true; float storeDashTime = dashTime; playerController.SetAbilityActive(true); playerController.myRigidbody.velocity = playerController.lastMove * dashSpeed; for (int i = 0; i < playerColliders.Length; i++) { if (i == 1) //finds the second collider available which is the sword's //ugly way to do this since it's hardcoded { storeSwordColliderSize = playerColliders[i].size; playerColliders[i].size = new Vector2(1, 1); } } yield return(new WaitForSeconds(dashTime)); for (int i = 0; i < playerColliders.Length; i++) //reverses what was done { if (i == 1) { playerColliders[i].size = storeSwordColliderSize; } } playerController.SetAbilityActive(false); dashTime = storeDashTime; dashing = false; }
void Update() { if (justAttacked) //if the player was just attacked by the enemy, start the counter { nextAttackCounter -= Time.deltaTime; } if (nextAttackCounter <= 0f) //if the counter ends, the enemy did not just attack and the counter is reset { justAttacked = false; nextAttackCounter = storeAttackCounter; } if (characterSelector.GetCharacterActive()) //checks if the character is active { charge = characterSelector.GetCharacterObject().GetComponentInChildren <Charge>(); //retrieved from the player's weapon roll = characterSelector.GetCharacterObject().GetComponentInChildren <Roll>(); chargeInvulnerable = charge.GetInvulnerable(); rollInvulnerable = roll.GetInvulnerable(); } }
void Update() { if (characterSelector.GetCharacterActive()) //checks if the character is active { playerHealthManager = characterSelector.GetCharacterObject().GetComponent <PlayerHealthManager>(); //get the instantiated (or active) player's PlayerHealthManager script maxHealth = playerHealthManager.GetMaxHealth(); //sets a variable to teh value of the character's max health currentHealth = playerHealthManager.GetCurrentHealth(); //sets a variable to teh value of the character's max health healthBar.maxValue = maxHealth; healthBar.value = currentHealth; //healthText.text = "HP: " + ((currentHealth / maxHealth) * 100).ToString() + "%"; //sets the health text to the player's current health as a percentage healthText.text = "HP: " + (currentHealth.ToString() + " / " + maxHealth.ToString()); //sets the health text to the player's current health over max health //changed to avoid decimal percentages (since the Warrior and Archer's health isn't 100) } }
public void PerformArrowSpray() //called when the player calls the ability { characterSelector = FindObjectOfType <CharacterSelector>(); playerController = characterSelector.GetCharacterObject().GetComponent <PlayerController>(); projectile = arrowPrefab.GetComponent <Projectile>(); animator = characterSelector.GetCharacterObject().GetComponent <Animator>(); playerFound = true; int storeDamageToDeal = projectile.GetDamageToDeal(); //stores the initial damage of the arrows prior to the change projectile.SetDamageToDeal(damagePerArrow); //changes the damage of the arrows temporarily firePoint = arrow.GetFirePoint(); firePoint2 = arrow.GetFirePoint(); firePoint3 = arrow.GetFirePoint(); myRigidbody = arrowPrefab.GetComponent <Rigidbody2D>(); myRigidbody.velocity = Vector2.zero; //prevents the player from sliding while attacking (stops the player) abilityTimeCounter = abilityTime; playerAbility = true; animator.SetBool("Ability", true); CheckLastMove(1); //checks the direction of the player for the first arrow GameObject newArrow = Instantiate(arrowPrefab, firePoint.position, firePoint.rotation); //fires the first arrow CheckLastMove(2); GameObject newArrow2 = Instantiate(arrowPrefab, firePoint2.position, firePoint2.rotation); CheckLastMove(3); GameObject newArrow3 = Instantiate(arrowPrefab, firePoint3.position, firePoint3.rotation); Destroy(newArrow, 5f); //set just in case the arrow doesn't collide with anything Destroy(newArrow2, 5f); Destroy(newArrow3, 5f); projectile.SetDamageToDeal(storeDamageToDeal); //set the arrow damage back to what it was set to before }
void Update() { playerController = FindObjectOfType <PlayerController>(); characterSelector = FindObjectOfType <CharacterSelector>(); levelTransitionManager = FindObjectOfType <LevelTransitionManager>(); if (characterSelector != null) //checks if characterSelector is active/not destroyed { if (characterSelector.GetCharacterActive()) //checks if the character is active { playerHealthManager = characterSelector.GetCharacterObject().GetComponent <PlayerHealthManager>(); //gets the current player instance's health manager } } scenesListLength = levelTransitionManager.GetScenesList().Count; chosenScenesListLength = levelTransitionManager.GetChosenScenesList().Count; }
void Update() { characterSelector = FindObjectOfType <CharacterSelector>(); audioManager = FindObjectOfType <AudioManager>(); try //hastily done because a non-gamebreaking error was being thrown once the player is killed { if (characterSelector.GetCharacterActive()) //checks if the character is active { playerHealthManager = characterSelector.GetCharacterObject().GetComponent <PlayerHealthManager>(); //gets the current player instance's health manager maxHealth = playerHealthManager.GetMaxHealth(); currentHealth = playerHealthManager.GetCurrentHealth(); } } catch { //pass } }
void Update() { characterSelector = FindObjectOfType <CharacterSelector>(); if (characterSelector != null) { if (characterSelector.GetCharacterActive()) //checks if the character is active { playerController = characterSelector.GetCharacterObject().GetComponent <PlayerController>(); //gets the current player instance's health manager if (!startPosSet) { startPosSet = true; playerController.transform.position = transform.position; //setting the player's position to the same position as the start point playerController.lastMove = startDirection; //The Vector2 variable, lastMove, in the PlayerController script was made public so it could be updated here } } } }
IEnumerator SwapLevelTimer() { if (!titleScreen) { try //chose to do this because an error that wasn't affecting the flow of the game was coming up { playerController.ResetMoveSpeedAndAttackTime(); } catch { //pass } characterSelector.GetCharacterObject().SetActive(false); } yield return(new WaitForSeconds(swapLevelTime)); if (selectRandomScene) //if the selectRandomScene boolean is active, then the gameobject the script is attached to wants to randomly load levels from a list { if (scenesListLength > 0 && (scenesListLength != chosenScenesListLength)) //if the array doesn't have any levels to select from, the code will not be run to avoid any errors { int randomSceneNum; bool available = false; while (!available) //if the specific random number that was chosen isn't in the list of levels (that holds the build indexes), then keep randomly choosing { randomSceneNum = Random.Range(1, scenesListLength + 1); //set to start at one since the Title Screen's index is 0 //had to add a +1 since the starting point was changed if (chosenScenesListLength > 0) { if (CheckChosenNum(randomSceneNum)) { levelTransitionManager.AddChosenScene(randomSceneNum); levelTransitionManager.SetLevelIndex(randomSceneNum); available = true; } } else { levelTransitionManager.AddChosenScene(randomSceneNum); levelTransitionManager.SetLevelIndex(randomSceneNum); available = true; } } if (!titleScreen && returnPlayerHealth) { playerHealthManager.SetCurrentHealth(playerHealthManager.GetCurrentHealth() + 50); //returns the player's health to the specified value if the fillPlayerHealth boolean is selected //playerHealthManager.SetCurrentHealth(playerHealthManager.GetMaxHealth()); //returns the player's health to full if the fillPlayerHealth boolean is selected } levelTransitionManager.FadeToLevel(); //loads the randomly selected level } else //will load the VictoryScreen if all levels are complete { gameOver = true; characterSelector.TurnOffCanvas(); levelTransitionManager.SetLevelIndex(SceneManager.sceneCountInBuildSettings - 2); //the penultimate level index is the Victory Screen but needs to be -2 because the index starts at 1 levelTransitionManager.FadeToLevel(); } } else { if (levelToLoad == "GameOverScreen") //string reference is slightly dangerous, but works fine { gameOver = true; characterSelector.TurnOffCanvas(); } SceneManager.LoadScene(levelToLoad); //loads a selected scene since random selection is not the desired functionality } }
public void SetTarget() //sets the target to be the player { target = characterSelector.GetCharacterObject().transform; }