Quantcast
Channel: Questions in topic: "error"
Viewing all articles
Browse latest Browse all 7934

How to fix my code? (Player death + Respawn)

$
0
0
Again, this was declined by the moderators overnight, so if this is against the rules, sorry, but I don't see why this would be rejected. (Last time it happened it was overnight as well) Okay, so I made this code so that after 2 seconds some stuff gets turned off, (Player death) and then the position is reset, and that stuff gets turned back on after five seconds, but i get and error saying Assets/Scripts/AttributeDeclaration.cs(131,14): error CS1624: The body of `AttributeDeclaration.KillPlayer()' cannot be an iterator block because `bool' is not an iterator interface type I am new to programming/coding, and have no clue what this means. Here is my code that I'm making (I have a lot going on in this, and a part of it has absolutley nothing to do with respawning, sorry. I wanted to get all of the player essentials into this one code.) Here is the code it is all in. using UnityEngine; using System.Collections; public class AttributeDeclaration : MonoBehaviour { #region Public ints public int Health = 100; public int Magic = 100; public int Strength = 100; public int Stamina = 100; public int Defense = 100; //Maximum attributes public int MaxHealth = 100; public int MaxMagic = 100; public int MaxStrength = 100; public int MaxStamina = 100; public int MaxDefense = 100; //Testing Stuff public int DamageAmount = 20; //--------------------------------------------------------------------------------------------- #endregion public PlayerLevelDeclaration PT; public PlayerMovement PM; public HealthPotion HP; //---------------------------------------------------------------------------------------- void Awake(){ newPos = transform.position; } //------------------------- // Use this for initialization void Start () { } //----------------------------------------------------------------------------------------- // Update is called once per frame void Update () { PT = gameObject.GetComponent(); HP = gameObject.GetComponent(); PM = gameObject.GetComponent(); TempDamageHealth(); TempDamageStamina(); TempDamageMagic(); TempDamageStrength(); TempDamageDefense(); CheckStats(); KillPlayer(); } //---------------------------------------------------------------------------------------- void CheckStats(){ if(Health <= 0) { Health = 0; } if(Stamina <= 0) { Stamina = 0; } if(Magic <= 0) { Magic = 0; } if(Strength <= 0) { Strength = 0; } if(Defense <=0) { Defense = 0; } } //----------------------------------------------------------------------------------------- public int TempDamageHealth() { if(Input.GetKeyDown(KeyCode.Keypad1)) { Health = Health - DamageAmount; } return Health; } //------------------------------------------------------------------------------------- public int TempDamageStamina() { if(Input.GetKeyDown(KeyCode.Keypad2)) { Stamina = Stamina - DamageAmount; } return Stamina; } //-------------------------------------------------------------------------------------- public int TempDamageMagic() { if(Input.GetKeyDown(KeyCode.Keypad3)) { Magic = Magic - DamageAmount; } return Magic; } //------------------------------------------------------------------------------------------ public int TempDamageStrength() { if(Input.GetKeyDown(KeyCode.Keypad4)) { Strength = Strength - DamageAmount; } return Strength; } //---------------------------------------------------------------------------------- public int TempDamageDefense() { if(Input.GetKeyDown(KeyCode.Keypad9)) { Defense = Defense - DamageAmount; } return Defense; } //-------------------------------------------------------------------- Vector3 newPos; bool IsAlive = false; bool KillPlayer(){ if(Health <= 0) { IsAlive = false; Health = 0; //Hopefully this makes it so the player can't move as soon as Health = 0, but doesn't disappear and lose //collision until after 2 seconds. Then, 5 seconds later, the player's position is set to 0, 0, 0, and //He regains movement, reappears, and regains collision. //Kill Player PM.enabled = false; yield return new WaitForSeconds(2f); renderer.enabled = false; collider.enabled = false; PM.enabled = false; //Wait 5 seconds yield return new WaitForSeconds(5f); //Set position code; Vector3 PlayerSpawn = new Vector3(0f , 0f , 0f); newPos = PlayerSpawn; transform.position = newPos; //Rest renderer.enabled = true; collider.enabled = true; PM.enabled = true; IsAlive = true; } } }

Viewing all articles
Browse latest Browse all 7934

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>