jueves, 3 de diciembre de 2015

Piedra, Papel o Tijera (Simplificado)

using UnityEngine;
using System.Collections;

public class PPT : MonoBehaviour {

public string jugadaP1, jugadaP2;

public int resultadoTirada;

// Use this for initialization
void Start () {

Debug.Log ("Bienvenido al torneo de Piedra, Papel y Tijera");
Debug.Log ("Pulsa Pied(R)a, (P)apel o (T)igera");





}

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

if (Input.GetKeyUp (KeyCode.R)) {
jugadaP1 = "Piedra";
jugadaP2 = GeneraJugadaIA();
ImprimeJugadas(jugadaP1, jugadaP2);
CompruebaResultados (jugadaP1,jugadaP2);


}

if (Input.GetKeyUp (KeyCode.P)) {
jugadaP1 = "Papel";
jugadaP2 = GeneraJugadaIA();
ImprimeJugadas(jugadaP1, jugadaP2);
CompruebaResultados (jugadaP1,jugadaP2);


}

if (Input.GetKeyUp (KeyCode.T)) {
jugadaP1 = "Tijera";
jugadaP2 = GeneraJugadaIA();
ImprimeJugadas(jugadaP1, jugadaP2);
CompruebaResultados (jugadaP1,jugadaP2);


}
}

string GeneraJugadaIA(){


resultadoTirada = Random.Range (1, 4);

if (resultadoTirada == 1) {
return "Piedra";


}

if (resultadoTirada == 2) {
return "Papel";


}

if (resultadoTirada == 3) {
return "Tijera";


} else
return "Error";


}
void CompruebaResultados (string jugadaP1, string jugadaP2){

if (jugadaP1 == jugadaP2) {
Debug.Log ("Empate");
}
if (jugadaP1 == "Piedra" && jugadaP2 == "Tijera") {
Debug.Log ("Gana el jugador 1");
}
if (jugadaP1 == "Piedra" && jugadaP2 == "Papel") {
Debug.Log ("Gana el jugador 2");
}
if (jugadaP1 == "Papel" && jugadaP2 == "Piedra") {
Debug.Log ("Gana el jugador 1");
}
if (jugadaP1 == "Papel" && jugadaP2 == "Tijera") {
Debug.Log ("Gana el jugador 2");
}
if (jugadaP1 == "Tijera" && jugadaP2 == "Papel") {
Debug.Log ("Gana el jugador 1");
}
if (jugadaP1 == "Tijera" && jugadaP2 == "Piedra") {
Debug.Log ("Gana el jugador 2");
}
}

void ImprimeJugadas(string jugadaP1, string jugadaP2){
Debug.Log ("El jugador 1 saca " + jugadaP1 + " y el jugador 2 saca " + jugadaP2);
}

}

Piedra, Papel o Tijera

using UnityEngine;
using System.Collections;

public class PPT : MonoBehaviour {

public string jugadaP1, jugadaP2;

public int resultadoTirada;

// Use this for initialization
void Start () {

Debug.Log ("Bienvenido al torneo de Piedra, Papel y Tijera");
Debug.Log ("Pulsa Pied(R)a, (P)apel o (T)igera");





}

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

if (Input.GetKeyUp (KeyCode.R)) {
jugadaP1 = "Piedra";
Debug.Log ("El P1 ha jugado " + jugadaP1);

resultadoTirada = Random.Range (1, 4);

if (resultadoTirada == 1) {
jugadaP2 = "Piedra";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 2) {
jugadaP2 = "Papel";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 3) {
jugadaP2 = "Tijera";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (jugadaP2 == "Piedra") {
Debug.Log ("Empate");
}
if (jugadaP2 == "Papel") {
Debug.Log ("Pierdes");
}
if (jugadaP2 == "Tijera"){
Debug.Log ("Ganas");
}



}

if (Input.GetKeyUp (KeyCode.P)) {
jugadaP1 = "Papel";
Debug.Log ("El P1 ha jugado " + jugadaP1);

resultadoTirada = Random.Range (1, 4);

if (resultadoTirada == 1) {
jugadaP2 = "Piedra";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 2) {
jugadaP2 = "Papel";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 3) {
jugadaP2 = "Tijera";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (jugadaP2 == "Piedra") {
Debug.Log ("Ganas");
}
if (jugadaP2 == "Papel") {
Debug.Log ("Empate");
}
if (jugadaP2 == "Tijera"){
Debug.Log ("Pierdes");
}
}

if (Input.GetKeyUp (KeyCode.T)) {
jugadaP1 = "Tijera";
Debug.Log ("El P1 ha jugado " + jugadaP1);

resultadoTirada = Random.Range (1, 4);

if (resultadoTirada == 1) {
jugadaP2 = "Piedra";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 2) {
jugadaP2 = "Papel";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (resultadoTirada == 3) {
jugadaP2 = "Tijera";
Debug.Log ("El P2 ha jugado " + jugadaP2);

}

if (jugadaP2 == "Piedra") {
Debug.Log ("Pierdes");
}
if (jugadaP2 == "Papel") {
Debug.Log ("Ganas");
}
if (jugadaP2 == "Tijera"){
Debug.Log ("Empate");
}
}
}
}

sábado, 30 de mayo de 2015

Cargar nivel y botones animados, Unity.

Cargar nivel y botones animados.

using UnityEngine;
using System.Collections;

public class UImanager : MonoBehaviour {
public Animator animplay;
public Animator animsettings;
public Animator animpanel;


// Use this for initialization
void Start () {

}

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

}

public void startgame(){
Application.LoadLevel ("Braidanim");

}

public void Onpressetsettings (){

animplay.SetBool ("estoy fuera", true);
animsettings.SetBool ("estoy fuera", true);
animpanel.SetBool ("estoy fuera", true);


}


public void Onpressetback (){
animplay.SetBool ("estoy fuera", false);
animsettings.SetBool ("estoy fuera", false);
animpanel.SetBool ("estoy fuera", false);


}

}

Contador de puntos, Unity.

Contador de puntos

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class Score : MonoBehaviour {
public static int score;
 Text text;



void Awake(){

text = GetComponent<Text> ();
score = 0;
}

// Use this for initialization


void Start () {

}

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

text.text = "Score:" + Character.score;

}
}

Movimiento ida y vuelta con rotación, Unity.

Movimiento ida y vuelta con rotación.


using UnityEngine;
using System.Collections;

public class enemy : MonoBehaviour {

public Vector3 move;
public float x;
public float y;

// Use this for initialization
void Start () {
x = -1;

}

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

transform.Translate (new Vector3 (x, 0, 0) * Time.deltaTime);

if (transform.position.x < -1.50) {
x=-1;

transform.rotation = Quaternion.Euler(new Vector3 (0, 180, 0));


}

if (transform.position.x > 4) {
x = -1;

transform.rotation = Quaternion.Euler (new Vector3 (0, 0, 0));
}
}
}

Mover y animar un personaje, Unity

Mover y animar un personaje


using UnityEngine;
using System.Collections;

public class Character : MonoBehaviour {

private Vector3 move;
private Animator animbraid;
private int speed;
private int speed2;
public static int score;

// Use this for initialization
void Start () {

animbraid = GetComponent<Animator> ();
speed = 3;
speed2 = 7;
score = 0;

}

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

animbraid.SetBool ("Idle", true);
animbraid.SetBool ("Walk", false);
animbraid.SetBool ("Jump", false);


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

animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", true);
animbraid.SetBool ("Jump", false);

transform.Translate (Vector3.right * Time.deltaTime * speed);
transform.rotation = Quaternion.Euler (new Vector3 (0, 0, 0));

}


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

animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", true);
animbraid.SetBool ("Jump", false);

transform.Translate (Vector3.right * Time.deltaTime * speed);
transform.rotation = Quaternion.Euler (new Vector3 (0, 180, 0));

}


if (Input.GetKey (KeyCode.W)) {

animbraid.SetBool ("Idle", false);
animbraid.SetBool ("Walk", false);
animbraid.SetBool ("Jump", true);

transform.Translate (Vector3.up * Time.deltaTime * speed2);

}




}
void OnTriggerEnter2D(Collider2D other){

if (other.gameObject.tag=="Coin"){
score=score+1;


}
if (other.gameObject.tag=="Coin"){

Destroy (other.gameObject);
}

if (other.gameObject.tag == "Enemy") {
Application.LoadLevel(Application.loadedLevel);

}

}

}