domingo, 17 de abril de 2016

Disparar proyectil

using UnityEngine;
using System.Collections;

public class disparo : MonoBehaviour {

public GameObject bala;

// Use this for initialization
void Start () {



}

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

if (Input.GetKeyDown ("space")) {
Instantiate (bala, transform.position, Quaternion.identity);
}

}
}

Movimiento Lateral

using UnityEngine;
using System.Collections;

public class playercontroller : MonoBehaviour {

float movimiento, velocidad;


// Use this for initialization
void Start () {

velocidad = 5;

}

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

movimiento = Input.GetAxis ("Horizontal");
GetComponent<Rigidbody> ().velocity = new Vector3 (movimiento * velocidad, GetComponent<Rigidbody> ().velocity.y);

}
}

AddForce

using UnityEngine;
using System.Collections;

public class fuerza : MonoBehaviour {

public GameObject bala;
public int velocidad;

void Start()
{

velocidad = 100;

}

void FixedUpdate()
{
bala.GetComponent<Rigidbody> ().AddForce (Vector3.forward * velocidad);

}
}

lunes, 1 de febrero de 2016

Player controller

Player controller

using UnityEngine;
using System.Collections;

public class playercontroller : MonoBehaviour {
float movimiento,velocidad,salto;
Animator anim;
// Use this for initialization
void Start () {
velocidad = 1.2f;
salto = 6f;
anim = GetComponent<Animator>();
}

// Update is called once per frame
void Update () {
movimiento = Input.GetAxis ("Horizontal");
GetComponent<Rigidbody2D> ().velocity = new Vector2 (movimiento * velocidad, GetComponent<Rigidbody2D> ().velocity.y);

if(movimiento > 0){
anim.SetBool("andarD",true);
anim.SetBool("andarI",false);
anim.SetBool("parado",false);
}

if(movimiento == 0){
anim.SetBool("andarD",false);
anim.SetBool("andarI",false);
anim.SetBool("parado",true);

}

if(movimiento < 0){
anim.SetBool("andarD",false);
anim.SetBool("andarI",true);
anim.SetBool("parado",false);
}
if (Input.GetKeyDown (KeyCode.UpArrow)) {


GetComponent<Rigidbody2D>().velocity = Vector2.up * salto;
anim.SetBool("parado",false);
}


}


}

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);


}

}