miércoles, 24 de febrero de 2021

Crear un contador de sumar puntos y un sonido de que suma puntos.

 


Crear un contador de sumar puntos y un sonido de que suma puntos.

Ahora a sumar puntos al aniquilar enemigos, muchas posibilidades con estas opciones, continua y continuara….mas la opción de que al herirme los enemigos voy perdiendo vida...con ambos desarrollos puedo hacer que el juego baya a otra escena mejorando algún tipo de arma o asunto al llegar a por ejemplo 500 de puntuacion, y, o, como en estas versiones se reinicie el videojuego al perder el player las 10 vidas.

  using UnityEngine;

// Include the namespace required to use Unity UI
using UnityEngine.UI;

using System.Collections;

public class bapuntos512 : 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 ()
    {


        // Assign the Rigidbody component to our private rb variable
        rb = GetComponent<Rigidbody>();

        // Set the count to zero 
        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 ("punto"))
    


        {
            // Make the other game object (the pick up) inactive, to make it disappear
            other.gameObject.SetActive (false);///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            // Add one to the score variable 'count'
            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 = "PUNTOS: " + count.ToString ();
        // Check if our 'count' is equal to or exceeded 12
        if (count >= 1111111) 
        //if (count >= 99) 
        {
            // Set the text value of our 'winText'
            winText.text = "JUEGO COMPLETADO";

            Destroy (gameObject, 1.2f); 

        

        }
    }
}
 

 

 

 

 

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

public class suenaalsumarpuntos : MonoBehaviour {


        public AudioSource tickSource;

        void Start () {


            tickSource = GetComponent<AudioSource> ();


        }

        void Update () {
        }

        void OnTriggerEnter(Collider other) {
            if (other.gameObject.CompareTag ("punto")){

                tickSource.Play ();



            }}

    }