jueves, 25 de marzo de 2021

Como hacer ítems de recuperar vidas con Unity



Como hacer ítems de recuperar vidas con Unity, aquí pongo los scripts en el blog, es muy sencillo solo se cambia una linea que pone el signo – menos por otra linea que pondremos el signo +mas, el mismo script pero con otro nombre y el mismo texto que utilizamos en el mismo camvas,

cuando toquemos los ítems que son unos cubos con la cruz roja sumara vidas el player cuando le alcances las balas del enemigos restara vidas el player en este caso el tag de sumar se llama “cruz” y el tag de restar se llama “pomada”.

 

  using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class restavidaamericanodeintrocuarta : MonoBehaviour {


        // Create public variables for player speed, and for the Text UI game objects
        public float speed;
        public Text countText;
        public Text winText;

        // Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
        private Rigidbody rb;
        private int count;/// <summary>



        // At the start of the game..
        void Start ()
        {

            rb = GetComponent<Rigidbody>();

            // Set the count to zero 
            //count = 0;////original
            count = 10;
            // Run the SetCountText function to update the UI (see below)
            SetCountText ();

            // Set the text property of our Win Text UI to an empty string, making the 'You Win' (game over message) blank
            winText.text = "";
        }


        void OnTriggerEnter(Collider other) 
        {


            if (other.gameObject.CompareTag ("pomada")){

                other.gameObject.SetActive (false);///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                // Add one to the score variable 'count'
                //count = count + 1;//////original
                count = count - 1;

                SetCountText ();
            }
        }

        // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
        void SetCountText()
        {


            // countText.text = "VIDAS: " + count.ToString ();///original
            countText.text = "AMERICANO VIDAS: " + count.ToString ();
            // Check if our 'count' is equal to or exceeded 12
            //if (count >= 10) ////original
            if (count <= 1) 

                //if (count >= 99) 
            {
                // Set the text value of our 'winText'
                winText.text = "TE HAN MATADO";

                //Destroy (gameObject, 1.2f); 
                Application.LoadLevel (3);


            }
        }
    }



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

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



using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class SUMAVIDASAMERICANOINTROCUARTA : MonoBehaviour {



        // Create public variables for player speed, and for the Text UI game objects
        public float speed;
        public Text countText;
        public Text winText;

        // Create private references to the rigidbody component on the player, and the count of pick up objects picked up so far
        private Rigidbody rb;
        private int count;/// <summary>



        // At the start of the game..
        void Start ()
        {

            rb = GetComponent<Rigidbody>();

            // Set the count to zero 
            //count = 0;////original
            count = 10;
        //count = 0;
            // Run the SetCountText function to update the UI (see below)
            SetCountText ();

            // Set the text property of our Win Text UI to an empty string, making the 'You Win' (game over message) blank
            winText.text = "";
        }


        void OnTriggerEnter(Collider other) 
        {


            if (other.gameObject.CompareTag ("cruz")){

                other.gameObject.SetActive (false);///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                // Add one to the score variable 'count'
                //count = count + 1;//////original
                count = count + 1;

                SetCountText ();
            }
        }

        // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
        void SetCountText()
        {


            // countText.text = "VIDAS: " + count.ToString ();///original
            countText.text = "AMERICANO VIDAS: " + count.ToString ();
            // Check if our 'count' is equal to or exceeded 12
            //if (count >= 10) ////original
            if (count <= 1) 

                //if (count >= 99) 
            {
                // Set the text value of our 'winText'
                winText.text = "TE HAN MATADO";

                //Destroy (gameObject, 1.2f); 
                Application.LoadLevel (3);


            }
        }
    }






😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄😄

👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👀👌👌👀👀👀👀👀👀👀👀

EJEMPLO DE ITEMS CON UNITY

👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌👌


👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄👄

COMO HACER PERSECUCIONES INTELIGENCIA ARTIFICIAL DE ENEMIGOS

 😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁😁