Unity Spain

Post Antiguos => General (Antiguo) => Mensaje iniciado por: ramunda en Julio 01, 2015, 02:24:57 PM

Título: Pausa antes de respawn aleatorio...
Publicado por: ramunda en Julio 01, 2015, 02:24:57 PM
Hola, mis queridos amigos necesito un consejo de nuevo
 
Quiero que antes de que mi PJ muera y respawnee en una posición aleatoria(eso funciona bien) , que tenga una pequeña pausa(posterior animación que ya vendra), le he insertado una pausa antes de que eso pase pero me tira un error muy raro que no se porque....
 
 
Adjunto script completo:

using UnityEngine;
using System.Collections;
    public class PlayerInfo : MonoBehaviour {
public GameObject healthBottle;
public GameObject player;
public AudioClip deathClip;
public AudioClip deathClip2;
public float length;
int health = 100;
int damageCount = 0;
int currentHealth;
bool playerFighting;
public GUIText healthbar;
float timer = 0.0f;
float healthTimer = 0.0f;
bool healthShouldRespawn = false;
// Use this for initialization
void Start () {
currentHealth = health;
}

// Update is called once per frame
void Update () {
   Cursor.visible = false;
   print("player in combat? " + playerFighting);
   if(!playerFighting){
      print("player is not fighting");
      if(currentHealth != 100){
         timer += Time.deltaTime;
         print ("timer: " + timer);
         if(timer > 90.0f){
            currentHealth += 10;
            timer = 0.0f;
         }
      }
   }
   else
   {
      if(currentHealth <= 0){
         GetComponent<AudioSource>().PlayOneShot(deathClip);length = 0.5f;
         yield return new WaitForSeconds (5);// esta linea es la de pausa y la que da problemas
         transform.position = new Vector3(Random.Range(50.0f, 120.0f), 0, Random.Range(10.0f, 200.0f));
         currentHealth = 100;
      }
   }
   healthbar.text = "Vida " + currentHealth + " / 100";
   if(healthShouldRespawn)
   {
      healthTimer += Time.deltaTime;
      if(healthTimer > 5.0f)
      {
         healthBottle.gameObject.SetActive(true);
         healthTimer = 0.0f;
      }
   }
}
public void ApplyDamage(int damage){
   damageCount = damageCount + damage;
   if(damageCount == 100){
      currentHealth = currentHealth - 30;
      GetComponent<AudioSource>().PlayOneShot(deathClip2);length = 0.2f;
      healthbar.text = "Health " + currentHealth + " / 100";
      damageCount = 0;
   }
   print(currentHealth);
}
public void playerInCombat(int combat){
   if(combat == 1){
      playerFighting = true;
   }
   else
   {
      playerFighting = false;
   }
}
void OnTriggerEnter(Collider item){
   if(item.gameObject.tag == "PlayerHealthBottle")
   {
      if(currentHealth < 100)
      {
         currentHealth = currentHealth + 50;
         item.gameObject.SetActive(false);
         healthShouldRespawn = true;
      }
   }
}
 
}

la linea 42...alli tengo la pausa....y me tira este error:
 
error CS1624: The body of `PlayerInfo.Update()' cannot be an iterator block because `void' is not an iterator interface type
 
 
Grrr alguna solucion a la vista?
 
Gracias de antemanoooo
 
 
 
 
 
 
Título: Pausa antes de respawn aleatorio...
Publicado por: kalua66 en Julio 01, 2015, 02:43:07 PM
//Esto donde te da error
if(currentHealth <= 0){
   GetComponent<AudioSource>().PlayOneShot(deathClip);length = 0.5f;
   Invoke("Respawn",5);
}
 
void Respawn(){
    transform.position = new Vector3(Random.Range(50.0f, 120.0f), 0, Random.Range(10.0f, 200.0f));
    currentHealth = 100;
}
Título: Pausa antes de respawn aleatorio...
Publicado por: ramunda en Julio 01, 2015, 03:42:26 PM
Cita de: kalua66 date=1435754587

//Esto donde te da error
if(currentHealth <= 0){
   GetComponent<AudioSource>().PlayOneShot(deathClip);length = 0.5f;
   Invoke("Respawn",5);
}
 
void Respawn(){
    transform.position = new Vector3(Random.Range(50.0f, 120.0f), 0, Random.Range(10.0f, 200.0f));
    currentHealth = 100;
}

Muchasss gracias por la pronta respuesta ..desgraciadamente no funciona ( me da este tumulo de errores....
 
error CS1547: Keyword `void' cannot be used in this context
 
error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `='
 
error CS8025: Parsing error
 
 
 
 
 
 
 
 
Título: Pausa antes de respawn aleatorio...
Publicado por: kalua66 en Julio 01, 2015, 04:03:09 PM

using UnityEngine;
using System.Collections;
    public class PlayerInfo : MonoBehaviour {
public GameObject healthBottle;
public GameObject player;
public AudioClip deathClip;
public AudioClip deathClip2;
public float length;
int health = 100;
int damageCount = 0;
int currentHealth;
bool playerFighting;
public GUIText healthbar;
float timer = 0.0f;
float healthTimer = 0.0f;
bool healthShouldRespawn = false;
        bool muerto= false;
// Use this for initialization
void Start () {
currentHealth = health;
}

// Update is called once per frame
void Update () {
   Cursor.visible = false;
   print("player in combat? " + playerFighting);
   if(!playerFighting){
      print("player is not fighting");
      if(currentHealth != 100){
         timer += Time.deltaTime;
         print ("timer: " + timer);
         if(timer > 90.0f){
            currentHealth += 10;
            timer = 0.0f;
         }
      }
   }
   else
   {
      if(currentHealth <= 0 && !muerto ){
                           muerto=true;
                           GetComponent<AudioSource>().PlayOneShot(deathClip);length = 0.5f;
                           Invoke("Respawn",5);
                        }
   }
   healthbar.text = "Vida " + currentHealth + " / 100";
   if(healthShouldRespawn)
   {
      healthTimer += Time.deltaTime;
      if(healthTimer > 5.0f)
      {
         healthBottle.gameObject.SetActive(true);
         healthTimer = 0.0f;
      }
   }
}
public void ApplyDamage(int damage){
   damageCount = damageCount + damage;
   if(damageCount == 100){
      currentHealth = currentHealth - 30;
      GetComponent<AudioSource>().PlayOneShot(deathClip2);length = 0.2f;
      healthbar.text = "Health " + currentHealth + " / 100";
      damageCount = 0;
   }
   print(currentHealth);
}
public void playerInCombat(int combat){
   if(combat == 1){
      playerFighting = true;
   }
   else
   {
      playerFighting = false;
   }
}
        void Respawn(){
          muerto=false;
          transform.position = new Vector3(Random.Range(50.0f, 120.0f), 0, Random.Range(10.0f, 200.0f));
          currentHealth = 100;
        }
void OnTriggerEnter(Collider item){
   if(item.gameObject.tag == "PlayerHealthBottle")
   {
      if(currentHealth < 100)
      {
         currentHealth = currentHealth + 50;
         item.gameObject.SetActive(false);
         healthShouldRespawn = true;
      }
   }
}
 
}
Título: Pausa antes de respawn aleatorio...
Publicado por: ramunda en Julio 01, 2015, 09:11:40 PM
Kalua66, sin palabras, e aprendido mas mirando el script corregido que me has dejado que mirando 100 tutoriales, no tengo palabras para darte las gracias.
 
Ahora si , tarda 5 segundos y respawn, eso va de maravilla solo que la vida se le va a -20 -30 pero eso es lo de menos ya inventare algo para que salga un menu o algo y le diga respawn o lo que sea.
 
De nuevo , gracias , un abrazo