jueves, 17 de agosto de 2023

scripts en C# Unity de barra de vida ganar vida y barra de vida perder vida;

 

 

 



https://www.youtube.com/watch?v=JbFlzZAQxZA&t=2s

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class datosjugador : MonoBehaviour
{
    public int vidaPlayer = 1000;//INBENTO PONER 1000
    public Slider vidaVisual;
        private void Update()

        {

        vidaVisual.GetComponent<Slider>().value = vidaPlayer;//INBENTO =1000;

      //  if (vidaPlayer <= 1000)// IMBENTO 1000 EL ORIGINAL 0--estaba asi
            if (vidaPlayer <=1)// IMBENTO 1000 EL ORIGINAL 0
        {

            Debug.Log("game over");


            Application.LoadLevel(1);//imbento




        }
}
}

 

 --------------------------------------------------------------

------------------------------------------------------------------- 


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class boladamage : MonoBehaviour
{


    public int vidaPlayer = 1000;//IMBENTO TODA LA LINEA

    //  public int boti;//imbento
    public int damage;
    public GameObject Player;
    private void OnTriggerEnter(Collider other)
    {
        if (other.tag == "bobo")//original
           // if (other.tag == "yoyo")
            {

            Player.GetComponent<datosjugador>().vidaPlayer -= damage;


        }
     //   if (other.tag == "yoyo")//imbento yo
        {

           // Player.GetComponent<datosjugador>().vidaPlayer += boti;//imbento
          //  Player.GetComponent<datosjugador>().vidaPlayer += damage;//imbento

            //  Debug.Log("estoenemigo");//original
        }
    }
}

 

 ------------------------------------------------------------------------------

----------------------------------------------------------------------

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class boladavida : MonoBehaviour
{



    public int vidaPlayer = 1000;//IMBENTO TODA LA LINEA

    //  public int boti;//imbento
  //  public int damage = 50;//ORIGINAL
    public int damage = 1000;//IMBENTO

    public GameObject Player;
    private void OnTriggerEnter(Collider other)
    {
      //  if (other.tag == "yoyo")//original
          //  if (other.tag == "tutu")//imbento
                                      if (other.tag == "bobo")//deveria ser el correcto por que es el tag del player bobo el que toca
            {

           // Player.GetComponent<datosjugador>().vidaPlayer += damage;//ORIGINAL
            Player.GetComponent<datosjugador>().vidaPlayer = damage;//IMBENTO

        }
        //   if (other.tag == "yoyo")//imbento yo
        {

            // Player.GetComponent<datosjugador>().vidaPlayer += boti;//imbento
            //  Player.GetComponent<datosjugador>().vidaPlayer += damage;//imbento

            //  Debug.Log("estoenemigo");//original
        }
    }
}

 

 ----------------------------------------------------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------------------------------------

No hay comentarios:

Publicar un comentario