Mostrando entradas con la etiqueta c#. Mostrar todas las entradas
Mostrando entradas con la etiqueta c#. Mostrar todas las entradas

domingo, 21 de marzo de 2021

c#, disparos con Unity,

 


DISPARO A DISPARO LENTO----------------

  /// <summary>
/// Launcher.
/// 
/// 3/2/2013
/// Steve Peters
/// Game Developers Guild - Miami, FL
/// 
/// Allows us to launch projectiles at a wall. It preinstantiates and stores the projectiles in a 
/// stack to improve performance
/// </summary>
using UnityEngine;
using System.Collections;

public class Launcher : 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.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();
    }
}

 

 

 

  DISPARO A DISPARO RAFAGAS MUY RAPIDO IMITA AMETRALLADORA---------------

 

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

public class launchermasvelocidad : 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.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.1f;
                    }
                }    
            }

            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();
        }
    }

sábado, 20 de marzo de 2021

0,2,6 versión de warlike_feats,


 

0,2,6 versión de warlike_feats, pongo aquí esta ultima versión para jugarla y descargarla, si la queréis probar, y una captura de video, a apartir de aquí are sobre papel los siguientes niveles, versiones del videojuego para concretar mejor lo que quiero poner en las pantallas, de momento voy añadiendo atrezo para intentar darle el máximo ambiente de guerra de la época, y pondré un script para que al llegar a cierto numero de puntos se abra la 3 parte del videojuego, esto me va ir mas lento porque quiero basarme primero sobre lo escrito en papel y con dibujos de los escenarios y anotaciones , que también pondré en el blog durante estos próximos días…...