Sei sulla pagina 1di 7

BULLET HELL

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Player : MonoBehaviour {

public float xMin, xMax, zMin, zMax; //valores x&Z max min

private Rigidbody rb; // activar rigibody

public GameObject shot;

public Transform shotContent;

public float fireRate;//tiepo de disparo

public float nextFire;//tiempo entre cada disparo

//

public GameObject asteroid;

public Vector3 asteroidValues; // coordenadas

public int asteroidCount; //contador

public float asteroidWait; //tiempo de espera

public float startWait; //tiempo de re inicio

public float waveWait; //siguiente grupo

//

void Start () {

rb = GetComponent <Rigidbody> ();//activar rigibody

//

StartCoroutine(createAsteroids ()); //inicia asteroides

void Update(){

if(Input.GetButton("Fire1")&& Time.time > nextFire){ //evitar disparos muy seguido

nextFire = Time.time + fireRate;//tiempo entre shots

Instantiate (shot, shotContent.position, shotContent.rotation);//agrupar shots

//

GetComponent <AudioSource>().Play();//llamar al audio

//

// Update is called once per frame

void FixedUpdate () { ////////////////////////////a este anexamos fixed

float h = Input.GetAxis("Horizontal"); //obtener eje x //estas mueven con las flechas

float v = Input.GetAxis("Vertical");//obtener ehe y

Vector3 vector = new Vector3 (h, 5f, v); //posicion inicial //5f es la altura que elejimos
rb.velocity = vector * 10;//velocidad inicial //aqui ajustamos la velocidad de la nave cambinado el 10

rb.position = new Vector3 (//definir coordenadas limites x z

Mathf.Clamp (rb.position.x, xMin, xMax), 5.0f, // clamp = valores intermedios

Mathf.Clamp (rb.position.z, zMin, zMax)

);

rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -2); //giro mediante valor de grados Z

//Quatenion Euler = Tipo de rotacion

IEnumerator createAsteroids (){//crear asteroides continuos

yield return new WaitForSeconds (startWait);//reinicir asteroides

while (true){

for (int i = 0; i< asteroidCount; i++){//crear asteroides y dar rotacion

Vector3 spawnPosition = new Vector3

(Random.Range(-asteroidValues.x, asteroidValues.x),asteroidValues.y,asteroidValues.z);

//aleatorio de -x a +x

Quaternion spawnRotation = Quaternion.identity;//rotate

Instantiate (asteroid, spawnPosition, spawnRotation); // pos y rot asteriode

yield return new WaitForSeconds (asteroidWait);//tiempo entre objetos

yield return new WaitForSeconds (waveWait); //segunda ola de asteriodes

public class Parallax : MonoBehaviour {

public float speed = 0; // Use this for initialization

void Start () { }// Update is called once per frame

void Update () {

GetComponent <Renderer> ().material.mainTextureOffset = new Vector2 (0f, (Time.time * speed)% 1); //0f es X que esta en 0
//mover eje y
}}

lic class Destroy : MonoBehaviour {

void Start () { }

void Update () { }

void OnTriggerEnter(Collider other){ //dentro el collider

if(other.name == "Hit"){

return;}

Destroy(other.gameObject); //destruye el objeto


Destroy (gameObject);

void OnTriggerExit(Collider other){ //al salir del collider

Destroy (gameObject);
}
}

public class Rotation : MonoBehaviour {

public float rotation;

private Rigidbody rb; // Use this for initialization

void Start () {

rb = GetComponent <Rigidbody> ();

rb.angularVelocity = Random.insideUnitSphere * rotation; //velocidad angular aleatoria

}// Update is called once per frame

void Update () {

}
}

public class Move : MonoBehaviour {

public float speed;

void Start () {

GetComponent<Rigidbody> ().velocity = transform.forward * speed;

}// Update is called once per frame

void Update () {

}
}

MOVER CON QEWSAD

ing System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class move2 : MonoBehaviour {

public float deltaRotation = 45f;

public float deltaMovement = 2f;// Use this for initialization

void Start () { }// Update is called once per frame


void Update () {

Rotate ();

Movement ();

void Rotate () {

if (Input.GetKey (KeyCode.Q))
transform.Rotate (new Vector3 (0f, deltaRotation, 0f) * Time.deltaTime);

else if (Input.GetKey (KeyCode.E))


transform.Rotate (new Vector3 (0f, -deltaRotation, 0f) * Time.deltaTime);}

void Movement (){

if (Input.GetKey (KeyCode.W))
transform.Translate (Vector3.forward * deltaMovement * Time.deltaTime);

else if (Input.GetKey (KeyCode.S))


transform.Translate (Vector3.back* deltaMovement * Time.deltaTime);

else if (Input.GetKey (KeyCode.A))


transform.Translate (Vector3.left* deltaMovement * Time.deltaTime);

else if (Input.GetKey (KeyCode.D))


transform.Translate (Vector3.right* deltaMovement * Time.deltaTime);

Juego recolectar coints

sing System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

using UnityEngine.SceneManagement;

//contador: 0

public class Player : MonoBehaviour {

public float deltaRotation = 45f;

public float deltaMovement = 2f;

public float fuerza;

private Rigidbody rb;

public GameObject camara1;


private Vector3 mov;

public Text txtContador;

public Button btnReinicio;

public Button btnSiguiente; ////////////////////Adicione boton

private int puntos;//sumar coin

public Text txtTime;//reloj

private float timeValor; //valor eltiempo

// Use this for initialization

void Start () {

rb = GetComponent <Rigidbody> (); //obtener rigibody

mov = camara1.transform.position; //obtener posicion inicial cmara

puntos = 0; //iniciar cargador en 0

btnReinicio.gameObject.SetActive(false); //es un boleano que oculta el boton en el inicio //los boleanos son falso o verdadero

btnSiguiente.gameObject.SetActive(false);////////////////////Adicione boton

timeValor = 15; //tiempo inicial

// Update is called once per frame

void Update () {

Rotate ();

Movement ();

float h = Input.GetAxis ("Horizontal"); // obtener ejes x

float v = Input.GetAxis ("Vertical"); // obtener ejes y

Vector3 coordenada = new Vector3 (h, 0.5f, v); // ubicacion inicial

rb.AddForce(coordenada * fuerza * Time.deltaTime); // mover en ejes dependiendo

camara1.transform.position = this.transform.position + mov; //tomar posicion inical


timeValor -= Time.deltaTime; //tiempo en recerva

if (timeValor <= 0f){//cuando el relog llegue a cero

timeValor = 0.0f;//igual a cero

btnReinicio.gameObject.SetActive(true);//mostrar boton

}/*

else{//cuando el relog llegue a cero

timeValor = 0.0f;//igual a cero

btnReinicio.gameObject.SetActive(false);//mostrar boton

}*/

txtTime.text = "Tiempo: " + timeValor.ToString("F2");//mostrar dos caracteres de tiempo

//to string es una cadena

void Rotate (){ //rotacion

if (Input.GetKey (KeyCode.Q))

transform.Rotate (new Vector3 (0f, deltaRotation, 0f) * Time.deltaTime);

else if (Input.GetKey (KeyCode.E))

transform.Rotate (new Vector3 (0f, -deltaRotation, 0f) * Time.deltaTime);

void Movement () //movimiento

if (Input.GetKey (KeyCode.W))

transform.Translate (Vector3.forward * deltaMovement * Time.deltaTime);

else if (Input.GetKey (KeyCode.S))

transform.Translate (Vector3.back* deltaMovement * Time.deltaTime);


else if (Input.GetKey (KeyCode.A))

transform.Translate (Vector3.left* deltaMovement * Time.deltaTime);

else if (Input.GetKey (KeyCode.D))

transform.Translate (Vector3.right* deltaMovement * Time.deltaTime);

void OnTriggerEnter (Collider obj) {//entra run trigger

//Destroy (obj.gameObject);

if (obj.gameObject.tag == "coin"){ //etiqueta coin

obj.gameObject.SetActive(false); //ocultar objetos

puntos++;// suma de 1 en 1, si ponemos + 2 sua de dos

txtContador.text = "Contador: " + puntos.ToString();

if (puntos <= 2) {//las 6 coins

txtContador.text = "Ganaste"; //mostrar texto

btnSiguiente.gameObject.SetActive (true);//mostrar boton

}//en el examen van a ser dos botones revisar eso

}}

public void Elprimero(){

SceneManager.LoadScene("Main");// cargar escena "x" //////////////////Sustitui main por 1

public void Elsegundo(){

SceneManager.LoadScene("Main 2");// cargar escena "x" //////////////////Sustitui main por 2