--Originally published at Sierra's Blog
CLASS 1
//se ejecuta una vez al iniciar el gameobject
//no se sabe el orden de ejecución
void Awake(){
}
//se ejecuta después de todos los awake
//úsalo para inicialización
void Start(){
}
//se ejecuta una vez por frame
//pon aquí entradas de usuario y movimiento
void Update(){
}
void LateUpdate(){
}
//corre en un framerate fijo
void FixedUpdate(){
}
Class2 Collisions
// reference to other components
// all components have a corresponding class
private Transform t;
// atributos públicos
// primitivos y clases de unity pueden ser modificadas desde editor
public float velocidad;
//public GameObject go;
public Text text;
private Vector3 pos;
// Use this for initialization
void Start () {
// this can return null!!!!
// whenever you do this do it the least times possible
t = GetComponent<Transform> ();
// go = GameObject.Find (“Text”);
// text = go.GetComponent<Text> ();
text.text = “HOLA, SÍ JALÓ”;
pos = transform.position;
}
// Update is called once per frame
void Update () {
//t.Translate (0.01f, 0, 0);
// first issue – speed
// Time.deltaTime – keeps track of how much time passed since last frames
// input – 2 ways to catch input
// – directly pole from device
if(Input.GetKeyDown(KeyCode.A)){
//print (“KEY DOWN!”);
}
if (Input.GetKey (KeyCode.A)) {
//print (“JUST KEY.”);
}
if (Input.GetKeyUp (KeyCode.A)) {
//print (“KEY RELEASED!”);
}
if (Input.GetMouseButtonDown (0)) {
print (Input.mousePosition);
}
// – through axes (plural of axis)
float h = Input.GetAxis(“Horizontal”);
float v = Input.GetAxis (“Vertical”);
//print (h);
transform.Translate (h * velocidad * Time.deltaTime, v * velocidad * Time.deltaTime, 0, Space.World);
}
void OnCollisionEnter(Collision c){
print (c.contacts [0].point);
print (c.gameObject.transform.name);
}
void OnCollisionStay(Collision c){
//print (“stay”);
}
void OnCollisionExit(Collision c){
print(“exit”);
}
void OnTriggerEnter(Collider c){
print (“ENTER”);
Destroy (c.gameObject);
transform.position = pos;
}
void OnTriggerStay(Collider c){
}
void OnTriggerExit(Collider c){
}
Class 3 Physics
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Brick : MonoBehaviour {
private Rigidbody rb;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody> ();
Invoke (“Explotar”, 2);
}
// Update is called once per frame
void Update () {
}
void Explotar () {
rb.AddExplosionForce (2000, Vector3.zero, 10);
print (“si jala”);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Bullet : MonoBehaviour {
// retrieving a reference to a component
private Rigidbody rb;
// Use this for initialization
void Start () {
// this can always return null
rb = GetComponent<Rigidbody> ();
// -20
rb.AddForce (100 * transform.up, ForceMode.Impulse);
Destroy (gameObject, 3);
}
// Update is called once per frame
void Update () {
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Cannon : MonoBehaviour {
public GameObject originalBullet;
public Transform punta;
// Use this for initialization
void Start () {
StartCoroutine (EjemploDeCorutina ());
}
// Update is called once per frame
void Update () {
float h = Input.GetAxis (“Horizontal”);
transform.Translate (0, 0, h * Time.deltaTime * 5);
if(Input.GetKeyUp(KeyCode.Space)){
// do the shooting.
// instantiate – clone an object
// we need a reference to the original
//Instantiate(originalBullet);
// rotation – Quaternion – vector de 4 valores, expresa rotacion en un espacio tridimensional
Instantiate(originalBullet, punta.position, transform.rotation);
}
}
// coroutine – NO es concurrencia (pero parece!)
// pseudohilos
IEnumerator EjemploDeCorutina(){
while (true) {
yield return new WaitForSeconds (0.1f);
print (“hola”);
Instantiate(originalBullet, punta.position, transform.rotation);
}
}
}
Class4 KEN SPRITES
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Hadouken : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.Translate (-7 * Time.deltaTime, 0, 0, Space.World);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ken : MonoBehaviour {
public GameObject hadouken;
public Transform referencia;
private Animator a;
private float jAnterior;
// Use this for initialization
void Start () {
a = GetComponent<Animator> ();
jAnterior = 0;
}
// Update is called once per frame
void Update () {
float h = Input. Continue reading "C#" →