Noticias

¡RECUERDA QUE SI ERES UN NUEVO USUARIO, DEBES PRESENTARTE PARA PODER PUBLICAR MENSAJES! | TENEMOS CANAL OFICIAL DE TELEGRAM: t.me/unity3dspain

Necesito una idea...(RESUELTO)

Iniciado por ramunda, Noviembre 24, 2015, 08:44:07 PM

Tema anterior - Siguiente tema
Noviembre 24, 2015, 08:44:07 PM Ultima modificación: Noviembre 25, 2015, 01:05:03 AM por ramunda
Muy buenas a todos, necesito una idea,me intentare explicar lo mas claramente posible.Cree un sistema para cuando algun bixo me dañe, salga como una sangre en la pantalla con un Gui, bien hasta aqui ok , el scrip por si alguien le sirve es este:
sing UnityEngine;
using System.Collections;

public class BloodSplat : MonoBehaviour {
public Texture2D splat;
private float alpha = 1;
public float speed;
public bool test;
void OnGUI()
{
   if (alpha > 0.0)
   {
      Color color = Color.white;
      color.a = alpha;
      GUI.color = color;
      GUI.DrawTexture (new Rect(0, 0, Screen.width, Screen.height), splat);
      alpha -= speed*Time.deltaTime;
}}

void ApplyDamage ()
{
   alpha = 1f;
}

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

   {
      ApplyDamage();
   }

}
}
Esto funciona bien, el bicho me pega una yoya y se activa este script que esta en un empty GO. y lo llamo desde aqui (pongo el fragmento de codigo que lo llama que el resto es muy largo):
using UnityEngine;
using System.Collections;
public class skellyattackperro : MonoBehaviour {
public EnemyType myEnemyType;
private GameObject player;
public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;


    void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   // Update is called once per frame
   void Update () {
   if (!shotdamage) {
      sangre.SetActive (true);
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
      }
   }
   else
   {
      sangre.SetActive (false);
   }
Bien hasta aquí todo ok!, pero el problema viene cuando aplico esto a varios enemigos diferentes, lo que les pasa es que uno de los tantos funciona pero los demás dejan de funcionar.En parte lo entiendo, si todos tienesn lo mismo y activan y desactivan el objeto en si, llega un momento que se vuelve loco.Probé también , a poner el script directamente a mi personaje principal y que el script de los enemigos lo llamara y lo activara y desactivara , pero el resultado es el mismo.Tambien se me ocurrió duplicar el scrip que activa la sangre y re nombrarlo y llamarlo desde cada bicho con un nombre diferente, ej sangre1, sangre2...etc pero nada caos total de nuevo lo unico que tenia eran 30 sangres renombradas y seguía sin funcionar. Alguna idea de como hacer que esto funcione? Gracias de antemano!!!     

Noviembre 24, 2015, 11:25:54 PM #1 Ultima modificación: Noviembre 24, 2015, 11:28:18 PM por NicolasProner
Ese setactive al final esta mal. Porque estas desactivando por completo el componente. es como borrarlo:Al poner SetActive(false);Lo que haces es quitarlo y no volverlo a llamar a lo que cuando esto se quiera volver a reproducir no podra ya que SetActive lo quitó..Podrias intentar hacer:
if (!shotdamage)&&(sangre==true)/*o entiendo mucho js pero entiedes a lo que quiero llegar*/ {

      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
      }
   }
   else
   {

      sangre.SetActive (true);
            if (!shotdamage)&&(sangre==true)/*Esto va adentro de else no se porque me lo saca afuera*/{
              timer += Time.deltaTime;/*Esto tambien adentro de else*/
           if (timer >= 3) {
          shotdamage = true;
          timer = 0;
      }
   }
A lo que quiero llegar con esto es que intentes hacer algo parecido.  

[quote author=NicolasProner" data-ipsquote-contapp="forums" data-ipsquote-contenttype="forums" data-ipsquote-contentclass="forums_Topic" data-ipsquote-contentid="34514" data-ipsquote-contentcommentid="124057">Ese setactive al final esta mal. Porque estas desactivando por completo el componente. es como borrarlo:Al poner SetActive(false);Lo que haces es quitarlo y no volverlo a llamar a lo que cuando esto se quiera volver a reproducir no podra ya que SetActive lo quitó..Podrias intentar hacer:
if (!shotdamage)&&(sangre==true)/*o entiendo mucho js pero entiedes a lo que quiero llegar*/ {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
      }
   }
   else
   {

      sangre.SetActive (true);
            if (!shotdamage)&&(sangre==true)/*Esto va adentro de else no se porque me lo saca afuera*/{
              timer += Time.deltaTime;/*Esto tambien adentro de else*/
           if (timer >= 3) {
          shotdamage = true;
          timer = 0;
      }
   }
A lo que quiero llegar con esto es que intentes hacer algo parecido.  [/quote]Entiendo perfectamente lo que me quieres decir compañero, si es verdad me lo estoy cargando y por eso luego no funciona....Intentare algo , muchas gracias por la idea!! y no es JS es c# pero algo intentare , gracias!!!! 

Cita de: ramunda date=1448404314" data-ipsquote="" data-cite="ramunda" class="ipsQuoteEntiendo perfectamente lo que me quieres decir compañero, si es verdad me lo estoy cargando y por eso luego no funciona....Intentare algo , muchas gracias por la idea!! y no es JS es c# pero algo intentare , gracias!!!! 
Ahh disculpame, jaja bueno emm fijate a ver si te funciona o si no le mandamos skype y vemos juntos
Cita de: ramunda date=1448404314" data-ipsquote="" data-cite="ramunda" class="ipsQuoteEntiendo perfectamente lo que me quieres decir compañero, si es verdad me lo estoy cargando y por eso luego no funciona....Intentare algo , muchas gracias por la idea!! y no es JS es c# pero algo intentare , gracias!!!! 
Tambien despues del el if ultimo podrias ahi si agregarle SetActive(false);pero ya al volverse a reproducir esto se va a volver a activar

[quote author=NicolasProner" data-ipsquote-contapp="forums" data-ipsquote-contenttype="forums" data-ipsquote-contentclass="forums_Topic" data-ipsquote-contentid="34514" data-ipsquote-contentcommentid="124059">Ahh disculpame, jaja bueno emm fijate a ver si te funciona o si no le mandamos skype y vemos juntosTambien despues del el if ultimo podrias ahi si agregarle SetActive(false);pero ya al volverse a reproducir esto se va a volver a activar[/quote]mmm he probado lo que me comentabas pero..sin exito..no da fallo pero tampoco se activa ni funciona lo he dejado asi:
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   // Update is called once per frame
   void Update () {
   if (!shotdamage && sangre==true) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;

      }
   }

//      else
//      {
//         sangre.gameObject.SetActive(false);
//      }
 

Buenooo que tonto soy...lo tenia en las narices, gracias a tu idea lo he resuelto :), fijate:
private GameObject player;
public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;

   void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   
   // Update is called once per frame
void Update () {
   if (!shotdamage) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
         sangre.gameObject.SetActive(false);
      }
   }
      

   distance = Vector3.Distance(player.transform.position,gameObject.transform.position);
      
      if (distance <= 3) {
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("attack1");
      if (shotdamage) {
         shotdamage = false;
         character.ApplyDamage (damage);
         sangre.gameObject.SetActive(true);
      }
   }
tenia el if abajo que me lo decia claro...cuando no se aplique daño que se encienda o apague, y asi cada bixo lo llama segun su damage...con el else como tu bien has dicho simplemente lo mataba lo eliminaba...asi esta bien , dejo el script por si a alguien le sirve.Gracias Nicolas!!!  
Buenooo que tonto soy...lo tenia en las narices, gracias a tu idea lo he resuelto :), fijate:
private GameObject player;
public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;

   void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   
   // Update is called once per frame
void Update () {
   if (!shotdamage) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
         sangre.gameObject.SetActive(false);
      }
   }
      

   distance = Vector3.Distance(player.transform.position,gameObject.transform.position);
      
      if (distance <= 3) {
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("attack1");
      if (shotdamage) {
         shotdamage = false;
         character.ApplyDamage (damage);
         sangre.gameObject.SetActive(true);
      }
   }
tenia el if abajo que me lo decia claro...cuando no se aplique daño que se encienda o apague, y asi cada bixo lo llama segun su damage...con el else como tu bien has dicho simplemente lo mataba lo eliminaba...asi esta bien , dejo el script por si a alguien le sirve.Gracias Nicolas!!!  

 
    private bool shotdamage = false;
   
    void Update()
    {
        if (!shotdamage)
        {
            timer += Time.deltaTime;

            if (timer <= 3)
           
                sangre.gameObject.SetActive(true);
                shotdamage = true;
                timer = 0;

           
        }

        else
        {
            timer += Time.deltaTime;

            if (timer <= 3)
           
                sangre.gameObject.SetActive(false);
                shotdamage = false;
                timer = 0;

           
        }
 }
Prueba asin aver que tal.

[quote author=ramunda date=1448409716" data-ipsquote="" data-cite="ramunda" class="ipsQuote">Buenooo que tonto soy...lo tenia en las narices, gracias a tu idea lo he resuelto :), fijate:
private GameObject player;public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;

   void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   
   // Update is called once per frame
void Update () {
   if (!shotdamage) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
         sangre.gameObject.SetActive(false);
      }
   }
      

   distance = Vector3.Distance(player.transform.position,gameObject.transform.position);
      
      if (distance <= 3) {
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("attack1");
      if (shotdamage) {
         shotdamage = false;
         character.ApplyDamage (damage);
         sangre.gameObject.SetActive(true);
      }
   }
tenia el if abajo que me lo decia claro...cuando no se aplique daño que se encienda o apague, y asi cada bixo lo llama segun su damage...con el else como tu bien has dicho simplemente lo mataba lo eliminaba...asi esta bien , dejo el script por si a alguien le sirve.Gracias Nicolas!!!  Buenooo que tonto soy...lo tenia en las narices, gracias a tu idea lo he resuelto :), fijate:
private GameObject player;
public GameObject sangre;
private float distance;
public int damage =(10);
private PlayerInfo character;
private Animation myAnimation;
private float timer=0;
private bool shotdamage=true;

   void Start () {
   player = GameObject.Find ("Jugador");
   character = player.GetComponent<PlayerInfo>();
   myAnimation = gameObject.GetComponent<Animation>();
   }
   
   // Update is called once per frame
void Update () {
   if (!shotdamage) {
      timer += Time.deltaTime;
      if (timer >= 3) {
         shotdamage = true;
         timer = 0;
         sangre.gameObject.SetActive(false);
      }
   }
      

   distance = Vector3.Distance(player.transform.position,gameObject.transform.position);
      
      if (distance <= 3) {
      myAnimation.CrossFadeQueued("run", 0.3f, QueueMode.PlayNow);
      myAnimation.CrossFade("attack1");
      if (shotdamage) {
         shotdamage = false;
         character.ApplyDamage (damage);
         sangre.gameObject.SetActive(true);
      }
   }
tenia el if abajo que me lo decia claro...cuando no se aplique daño que se encienda o apague, y asi cada bixo lo llama segun su damage...con el else como tu bien has dicho simplemente lo mataba lo eliminaba...asi esta bien , dejo el script por si a alguien le sirve.Gracias Nicolas!!!  [/quote]De nada amigo... cualquier cosa mp

[quote author=brok" data-ipsquote-contapp="forums" data-ipsquote-contenttype="forums" data-ipsquote-contentclass="forums_Topic" data-ipsquote-contentid="34514" data-ipsquote-contentcommentid="124063">
private bool shotdamage = false;
   
    void Update()
    {
        if (!shotdamage)
        {
            timer += Time.deltaTime;

            if (timer <= 3)
           
                sangre.gameObject.SetActive(true);
                shotdamage = true;
                timer = 0;

           
        }

        else
        {
            timer += Time.deltaTime;

            if (timer <= 3)
           
                sangre.gameObject.SetActive(false);
                shotdamage = false;
                timer = 0;

           
        }
 }
Prueba asin aver que tal.[/quote]Muchas gracias Brok, tambien es una solucion , muchas gracias por la ayuda. 

Etiquetas: