Last active
August 24, 2021 20:50
-
-
Save ealbinu/b646bf621535940227fce63f5471a9dc to your computer and use it in GitHub Desktop.
Unity - Clase 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| Destroy(cosa.gameObject); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| public int recolectados; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| recolectados = 0; | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| recolectados++; | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| public int recolectados; | |
| public Text TXTrecolectado; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| recolectados = 0; | |
| ActualizarTXTRecolectados(); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| recolectados++; | |
| ActualizarTXTRecolectados(); | |
| } | |
| } | |
| void ActualizarTXTRecolectados() { | |
| TXTrecolectado.text = recolectados.ToString(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| public int recolectados; | |
| public Text TXTrecolectado; | |
| public Text TXTWin; | |
| private Rigidbody rb; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| recolectados = 0; | |
| ActualizarTXTRecolectados(); | |
| TXTWin.gameObject.SetActive(false); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| recolectados++; | |
| ActualizarTXTRecolectados(); | |
| } | |
| } | |
| void ActualizarTXTRecolectados() { | |
| TXTrecolectado.text = recolectados.ToString(); | |
| if(recolectados >= 4) { | |
| TXTWin.gameObject.SetActive(true); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| public int recolectados; | |
| public Text TXTrecolectado; | |
| public Text TXTWin; | |
| public Button BTNComenzar; | |
| private Rigidbody rb; | |
| private bool comenzar; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| recolectados = 0; | |
| ActualizarTXTRecolectados(); | |
| TXTWin.gameObject.SetActive(false); | |
| comenzar = false; | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| if(comenzar) { | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| recolectados++; | |
| ActualizarTXTRecolectados(); | |
| } | |
| } | |
| void ActualizarTXTRecolectados() { | |
| TXTrecolectado.text = recolectados.ToString(); | |
| if(recolectados >= 4) { | |
| TXTWin.gameObject.SetActive(true); | |
| } | |
| } | |
| public void comenzarjuego() { | |
| comenzar = true; | |
| BTNComenzar.gameObject.SetActive(false); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UnityEngine.UI; | |
| public class PlayerScript : MonoBehaviour | |
| { | |
| public int velocidad; | |
| public int recolectados; | |
| public Text TXTrecolectado; | |
| public Text TXTWin; | |
| public Button BTNComenzar; | |
| private Rigidbody rb; | |
| private bool comenzar; | |
| private GameObject[] cosas; | |
| //Asignación de variables | |
| void Start() { | |
| rb = GetComponent<Rigidbody>(); | |
| recolectados = 0; | |
| ActualizarTXTRecolectados(); | |
| TXTWin.gameObject.SetActive(false); | |
| comenzar = false; | |
| cosas = GameObject.FindGameObjectsWithTag("CosaBuena"); | |
| } | |
| //Con física | |
| void FixedUpdate() { | |
| //Mover Player | |
| float movimientoX = Input.GetAxis("Horizontal"); | |
| float movimientoZ = Input.GetAxis("Vertical"); | |
| Vector3 movimiento = new Vector3(movimientoX, 0.0f, movimientoZ); | |
| if(comenzar) { | |
| rb.AddForce(movimiento * velocidad); | |
| } | |
| } | |
| //Colisión con objetos Trigger | |
| void OnTriggerEnter(Collider cosa) { | |
| if(cosa.gameObject.CompareTag("CosaBuena")){ | |
| //Destroy(cosa.gameObject); | |
| cosa.gameObject.SetActive(false); | |
| recolectados++; | |
| ActualizarTXTRecolectados(); | |
| } | |
| } | |
| void ActualizarTXTRecolectados() { | |
| TXTrecolectado.text = recolectados.ToString(); | |
| if(recolectados >= 4) { | |
| TXTWin.gameObject.SetActive(true); | |
| } | |
| } | |
| public void comenzarjuego() { | |
| comenzar = true; | |
| BTNComenzar.gameObject.SetActive(false); | |
| } | |
| public void resetjuego() { | |
| //Posicion del Player | |
| transform.position = new Vector3(0,2,0); | |
| //Recolectados | |
| recolectados = 0; | |
| ActualizarTXTRecolectados(); | |
| //Ocultar etiqueta win | |
| TXTWin.gameObject.SetActive(false); | |
| //Mostrar btn comenzar | |
| comenzar = false; | |
| BTNComenzar.gameObject.SetActive(true); | |
| //Mostar recolectables | |
| foreach (GameObject cosa in cosas) { | |
| cosa.gameObject.SetActive(true); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| public class ScriptCamara : MonoBehaviour | |
| { | |
| public GameObject player; | |
| private Vector3 ubicacion; | |
| void Start(){ | |
| ubicacion = transform.position - player.transform.position; | |
| } | |
| void Update(){ | |
| transform.position = player.transform.position + ubicacion; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment