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

}

}

}