Documentos de Académico
Documentos de Profesional
Documentos de Cultura
void Update () {
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, mo
veVertical);
rb.AddForce (movement * velocidad);
}
}
1. 2. SALTO Y VELOCIDAD2
private bool salto;
private bool isGrounded;
public float poderSalto;
private float velocidad2 =500.0f;
Script: Botón
using UnityEngine.UI;
using UnityEngine.SceneManagement;
7. PERDER VIDAS
Primero, creamos el respawn: Create Empty object. Colocamos debajo del plano, +
AddComponent/BoxCollider: ampliamos la escala X y Z, que ocupe un gran área.
Creamos y añadimos el tag: “respawn”.
Create/Empty object. Lo llamamos “jugador”. Y lo ponemos en la posición en la que
queramos que aparezca la bola al volver a empezar.
En el canvas duplicamos el texto e imagen de los coleccionables. Cambiamos sus
nombres y les ponemos la imagen de las vidas. Los colocamos.
Duplico la escena, y la nombro como GameOver. La pongo en el build.
Script: Respawn:
public GameObject jugador;
Script respawn:
using UnityEngine.UI;
using UnityEngine.SceneManagement;
if (vidas <= 0) {
SceneManager.LoadScene ("GameOver");
}
}
}
}
8. COMENZAR EL JUEGO
En el GameOver, editamos el botón siguiente. Text = comenzar. Creo un script para este
botón nuevo.
using UnityEngine.SceneManagement;
9. AÑADIR MÚSICA
Creo empty/Add Component/AudioSource. Inserto la música en audioclip. Activo
LOOP.
Crear script: música.
void Awake (){
DontDestroyOnLoad (this.gameObject);
}
}
**Aplicamos el script al objeto vacío que contiene la música. Creamos y añadimos el
tag: sonar. Metemos este objeto vacío en la carpeta prefab, y lo borramos de hierarchy.
10. CONTADOR
Script respawn: (OJO!!! SE RESUME LAS LÍNEAS DE
vidas = vidas - 1; misVidas.text = vidas.ToString (); EN EL “VIDORRAS”, Por tanto,
borramos estas líneas y les ponemos Vidorras (); como se muestra en el script:
public Text contador;
private float tiempo;
private float tiempoFinal;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
}
}
SCRIPT BOTÓN
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
void Vidorras () {
vidas = vidas - 1;
misVidas.text = vidas.ToString ();
if (vidas <= 0) {
SceneManager.LoadScene ("GameOver");
}
SCRIPT MÚSICA
using System.Collections;
using System.Collections.Generic;
using UnityEngine;