domingo, 6 de marzo de 2022

Scripts en C# Unity definitivos para disparar y para que te disparen los enemigos.;

Este para que un enemigo dispare al player.

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

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

public class disparo : MonoBehaviour {

    public Transform player;

    public float range = 4f;
    public float bulletImpulse = 0.1f;

    private bool onRange = false;

    public Rigidbody projectile;

    void Start()
    {
        float rand = Random.Range(1.0f, 2.0f);
        InvokeRepeating("Shoot", 2, rand);
    }

    void Shoot()
    {

        if (onRange)
        {

            Rigidbody bullet = (Rigidbody)Instantiate(projectile, transform.position + transform.forward, transform.rotation);
            bullet.AddForce(transform.forward * bulletImpulse, ForceMode.Impulse);

            Destroy(bullet.gameObject, 2);
        }


    }

    void Update()
    {

        onRange = Vector3.Distance(transform.position, player.position) < range;

        if (onRange)
            transform.LookAt(player);
    }


}

 

 

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

Este para disparar el player 

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

 

  using UnityEngine;
using System.Collections;

public class Launcher2 : MonoBehaviour
{

    public Rigidbody projectile;
    public Rigidbody explosiveProjectile;
    public float launchspeed = 50;
    public bool useExplodingProjectiles = false;

    private float _LaunchDelayTime = 0.0f;

    public int stackSize = 60;            
    public Transform launchHole1;
    public Transform launchHole2;

    private Stack _Projectiles;
    private Stack _ExplosiveProjectiles;
    private Transform _myTransform;

    // Use this for initialization
    void Start ()
    {
        _myTransform = transform;
        _Projectiles = new Stack();
        if(useExplodingProjectiles)
        {
            _ExplosiveProjectiles = new Stack();
        }

        for(int i = 0; i <  stackSize; i++)
        {
            Rigidbody tr = Instantiate (projectile, _myTransform.position, _myTransform.rotation) as Rigidbody;
            PushProjectile(tr);

            if(useExplodingProjectiles)
            {
                Rigidbody rr = Instantiate (explosiveProjectile, _myTransform.position, _myTransform.rotation) as Rigidbody;
                PushExplosiveProjectile(rr);
            }
        }
    }

    // Update is called once per frame
    void Update ()
    {
        if(_Projectiles.Count > 0)
        {
            if(Time.time > _LaunchDelayTime)
            {    






                //if (Input.GetKeyDown(KeyCode.Space))
                if (Input.GetKey (KeyCode.M)) /////////////////imbentadooooooooooooooooooooooooooooooooooooo
                //if (Input.GetButton ("Fire1")) ////ametralladora
                    //    if (Input.GetButtonDown ("Fire1")) original tiro a tiro




                {
                    Rigidbody tr = PopProjectile();
                    tr.gameObject.SetActive(true);
                    tr.transform.position = launchHole1.position;
                    tr.transform.rotation = launchHole1.rotation;
                    tr.velocity = transform.TransformDirection (Vector3.forward * launchspeed);

                    tr = PopProjectile();
                    tr.gameObject.SetActive(true);
                    tr.transform.position = launchHole2.position;
                    tr.transform.rotation = launchHole2.rotation;
                    tr.velocity = transform.TransformDirection (Vector3.forward * launchspeed);

                    _LaunchDelayTime = Time.time + 0.5f;
                }
            }    
        }

        if(useExplodingProjectiles)
        {
            if(_ExplosiveProjectiles.Count > 0)
            {
                if(Time.time > _LaunchDelayTime)
                {    
                    if (Input.GetButtonDown ("Fire2")) 
                    {
                        Rigidbody tr = PopExplosiveProjectile();
                        tr.gameObject.SetActive(true);
                        tr.transform.position = launchHole1.position;
                        tr.transform.rotation = launchHole1.rotation;
                        tr.velocity = transform.TransformDirection (Vector3.forward * launchspeed);

                        tr = PopExplosiveProjectile();
                        tr.gameObject.SetActive(true);
                        tr.transform.position = launchHole2.position;
                        tr.transform.rotation = launchHole2.rotation;
                        tr.velocity = transform.TransformDirection (Vector3.forward * launchspeed);

                        _LaunchDelayTime = Time.time + 0.5f;
                    }
                }    
            }
        }
    }

    public void PushProjectile(Rigidbody x)
    {
        x.gameObject.SetActive(false);
        _Projectiles.Push(x);
    }

    public Rigidbody PopProjectile()
    {
        return (Rigidbody)_Projectiles.Pop();
    }

    public void PushExplosiveProjectile(Rigidbody x)
    {
        x.gameObject.SetActive(false);
        _ExplosiveProjectiles.Push(x);
    }

    public Rigidbody PopExplosiveProjectile()
    {
        return (Rigidbody)_ExplosiveProjectiles.Pop();
    }
}

 

 

 Aqui enlace donde aprendi que enmigos  disparen a Player (protagonista de posible videojuego) hace años buscaba una solucion buena.

https://futbolstudiohistorietas.com/unity-parte-4-enemigos-disparan/

 

 

jueves, 3 de marzo de 2022

Como hacer una puerta giratoria con Unity sin programación.

 


Como hacer una puerta giratoria con unity sin programación.

Se hace un cubo y a partir de el se moldea estirándolo ...(todo esto desde Unity no es necesario blender)… asta darle forma rectangular y aplanada de una puerta bastante ancha para que quepan personajes al pasar por ella.

La puerta a de tener el Box Collider y el Rigidbody como se ve en la captura de pantalla.



súper sencillo los personajes al pasar hacen girar la puerta, fijarse en el detalle que provoca esto...Constraints y los Freeze Position y los Freeze Rotation desde Rigidbody...marcar los ejes x-y-z como se ve en la captura de pantalla, es lo que hace que la puerta no caiga al suelo o salga volando o cualquier historia...solo hace lo que tiene que hacer una puerta giratoria, girar cuando la empujan.

Para el cristal de la puerta para hacer ese efecto, también fijarse en la captura de pantalla ...UI/Unlit/Transparent.

La textura esta pintada con la herramienta gratuita GIMP 2.10.12 con un fondo transparente y guardada en formato PNG que es el que soporta las transparencias.



sábado, 26 de febrero de 2022

Pinball detalles con C# game over reinicios de juego y de pantallas niveles del videojuego;

 

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

public class DESTRUYEYPASAANIVEL3 : MonoBehaviour {


        void Start () {

            //tickSource = GetComponent<AudioSource> ();



        }

        void Update () {
        }

        void OnTriggerEnter(Collider other) {
            //if (other.gameObject.CompareTag ("avismo")){
            //if (other.gameObject.CompareTag ("ogri2")){
            if (other.gameObject.CompareTag ("juegopierdo")){
                //transform.Rotate (new Vector3 (0 * Time.deltaTime, 91, 90), Space.Self);

                //tickSource.Play ();
                Destroy (gameObject, 2.0f); 



                    Application.LoadLevel (3);/////7originalllllllllllllllllllllllllllll



            }}

    }

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

 

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

----------

  using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;/// <summary>
public class reiniciojuego2 : MonoBehaviour {


        public Text contador1;
        public Text fin1;
        private float tiempo = 8f;


//    void Awake() {

    //}

        // Use this for initialization
        void Start () {
            contador1.text = " " + tiempo;
            fin1.enabled = false;

        }

        // Update is called once per frame
        void Update ()
        {
        
            tiempo -= Time.deltaTime;
            contador1.text = " " + tiempo.ToString ("f0");
            if (tiempo <= 0) {
                contador1.text = "0";
                fin1.enabled = true;

                {
                    //void OnTriggerEnter(Collider other) {
                    //if (other.gameObject.CompareTag ("ogri2 (1)CAMPEONNNNNNNNNNNNNNNNNNN")){

                //    Destroy (gameObject, 0.0f); 

                    {

                        //Application.LoadLevel (1); ESTE ES EL ORIGINALLLLLLL

                        Application.LoadLevel (0);

                    }
                }
            }
        }

    }
---------------------------------------------------------------------

Detalles que se me olvido comentar en el video son por ejemplo un bug que tenia cuando la bola salia pitando como una bala y no retornaba a sus coordenadas por que no tocaba los gameobjects que producían esa accion, lo resolví poniendo un enorme cubo de color negro de fondo y aplanado como un plano con el correspondiente tag “cordena”, así la bola hiciese lo que hiciese si se salia del juego daba hay y volvia a sus coordenadas…..también añado el script que tiene la escena de gameover para que transcurridos 8 segundos se reinicie el juego si se pierden las 3 bolas…...

miércoles, 23 de febrero de 2022

C# niveles con unity;

 


En breves instantes video explicativo........

  using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AUMENTAPUNTOSP : 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>

        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 = "";
        }

        // store a reference to that collider in a variable named 'other'..
        void OnTriggerEnter(Collider other) 
        {

            //if (other.gameObject.CompareTag ("ogri2"))
            if (other.gameObject.CompareTag ("MATA"))
        //if (other.gameObject.CompareTag ("lateral"))
            {

                // Make the other game object (the pick up) inactive, to make it disappear
//                other.gameObject.SetActive (false);////ESTO DE AQUI SI ESTA ACTIVADO BORRA EL GRAFICO GIRATORIO MUY OMPORTANTISIMO

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


                // Run the 'SetCountText()' function (see below)
                SetCountText ();
            }
        }

        // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
        void SetCountText()
        {
            // Update the text field of our 'countText' variable
            //countText.text = "Count: " + count.ToString ();

            countText.text = "PUNTOS: " + count.ToString ();
            // Check if our 'count' is equal to or exceeded 12
            //if (count == 11) 
                //if (count >= 11) /////////original
                if (count >= 44) ////////7original
            {

        //    Destroy (gameObject);

            Application.LoadLevel (1);/////7originalllllllllllllllllllllllllllll

            }
        }
    }


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

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

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


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AUMENTAPUNTOSPlateral : 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>

        void Start ()
        {

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

            // Set the count to zero 
            count = 44;

            // 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 = "";
        }

        // store a reference to that collider in a variable named 'other'..
        void OnTriggerEnter(Collider other) 
        {

            //if (other.gameObject.CompareTag ("ogri2"))
            //if (other.gameObject.CompareTag ("MATA"))
        if (other.gameObject.CompareTag ("lateral"))
            {


                // Make the other game object (the pick up) inactive, to make it disappear
//                other.gameObject.SetActive (false);////ESTO DE AQUI SI ESTA ACTIVADO BORRA EL GRAFICO GIRATORIO MUY OMPORTANTISIMO


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


                // Run the 'SetCountText()' function (see below)
                SetCountText ();
            }
        }

        // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
        void SetCountText()
        {
            // Update the text field of our 'countText' variable
            //countText.text = "Count: " + count.ToString ();

            countText.text = "PUNTOS: " + count.ToString ();
            // Check if our 'count' is equal to or exceeded 12
            //if (count == 11) 
                //if (count >= 11) /////////original
                if (count >= 4) ////////7original
            {

        //    Destroy (gameObject);

            //Application.LoadLevel (1);/////7originalllllllllllllllllllllllllllll

            }
        }
    }




lunes, 21 de febrero de 2022

Como hacer un pinball con unity sin tener ni idea y asu vez meterlo en otro videojuego echo tambien sin tener ni idea.;

Como hacer un pinball con unity sin tener ni idea y asu vez meterlo en otro videojuego echo tambien sin tener ni idea.;

 

Videojuego THE WOLF MAN OF THE UNDERGROUND beta;

siguiendo este videojuego voy a insertar minijuegos en el, la idea es que en momentos dados el jugador que maneja al hombre lobo desconecte del entorno y se baya por ejemplo a un salón recreativo a jugar a la maquina del millón, la de pegarle a la bola y sumar puntos asta conseguir partidas extra,,,, en este caso seria avanzar en otros niveles del videojuego…..lo estoy haciendo así para ver si descanso del juego de su construcción y luego vuelvo a retomarlo alternando unos temas con otros y compaginándolos en el mismo videojuego de THE WOLF MAN OF THE UNDERGROUND

domingo, 13 de febrero de 2022

PINBALL SCRIPTS EN C# PARA CONSTRUIR EL VIDEOJUEGO;

 


 

 

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

public class empujafuerteportagestenombre : MonoBehaviour {



        // public float thrust;
        public Rigidbody rb;

        void Start()
        {
            rb = GetComponent<Rigidbody>();
        }

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

                rb.AddForce(0.0f, 0f, 177.0f, ForceMode.Impulse);


            }
        }


    }


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

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

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

public class altocartagcambialascoordenadas : MonoBehaviour {


        // Use this for initialization
        void Start()
        {

            //transform.rotation = Quaternion.Euler (0,45, 0);
        }



    void Update()
    {
    }

    //void OnCollisionEnter (Collision collision){
    //    if (collision.gameObject.tag == "PUYO modelo"){


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


            transform.position = new Vector3 (-38.5f,8.6f, -14.7f);


        }
    }

}

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

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


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

public class altocartaggiraluzfoco : MonoBehaviour {



        // Use this for initialization
        void Start()
        {

            //transform.rotation = Quaternion.Euler (0,45, 0);
        }


//    float x;/// imbentado


        void Update()
        {
        }

        //void OnCollisionEnter (Collision collision){
        //    if (collision.gameObject.tag == "PUYO modelo"){


        void OnTriggerEnter(Collider other)
        {
            //if (other.gameObject.CompareTag("luzgira"))
        if (other.gameObject.CompareTag("MATA"))
            {


                transform.position = new Vector3 (29.24f,38.13f, -60.19f);//////este funcionaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
            //transform.rotation = new Vector3 (-38.5f,8.6f, -14.7f);

            //transform.rotation = new Vector3  (0.4f, 5.1f, 1.1f);
            //transform.rotation = Quaternion.Euler (0, 5, 0);


            //x += Time.deltaTime * 0.2f;
             
        //    transform.rotation = Quaternion.Euler (x, 0, 0);


            }
        }

    }


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

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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AUMENTAPUNTOSP : 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>

        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 = "";
        }

        // store a reference to that collider in a variable named 'other'..
        void OnTriggerEnter(Collider other) 
        {

            //if (other.gameObject.CompareTag ("ogri2"))
            if (other.gameObject.CompareTag ("MATA"))

            {








                // Make the other game object (the pick up) inactive, to make it disappear
//                other.gameObject.SetActive (false);////ESTO DE AQUI SI ESTA ACTIVADO BORRA EL GRAFICO GIRATORIO MUY OMPORTANTISIMO







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


                // Run the 'SetCountText()' function (see below)
                SetCountText ();
            }
        }

        // Create a standalone function that can update the 'countText' UI and check if the required amount to win has been achieved
        void SetCountText()
        {
            // Update the text field of our 'countText' variable
            //countText.text = "Count: " + count.ToString ();

            countText.text = "PUNTOS: " + count.ToString ();
            // Check if our 'count' is equal to or exceeded 12
            //if (count == 11) 
                //if (count >= 11) /////////original
                if (count >= 40) ////////7original
            {







            Application.LoadLevel (1);





            }
        }
    }



CONTINUARA......ESTA EN CONSTRUCCION.........................................................................

..........................