Carrinho com moedas e power-up

Códigos

PLAYER


using UnityEngine;
using System.Collections;



public class Player : MonoBehaviour
{
	// Quanto para esquerda ou direita o jogador ira quando apertar os botoes
	// This can be changed in the Inspector window
	public Vector2 esquerda = new Vector2(-10, 0);
	public Vector2 direita = new Vector2(10, 0);

	int dinheiro = 0;

	// Update is called once per frame
	void Update ()
	{
		// Esquerda
		if (Input.GetKey(KeyCode.LeftArrow))
		{
			rigidbody2D.AddForce(esquerda);

		}

		// Direita
		if (Input.GetKey(KeyCode.RightArrow))
		{
			rigidbody2D.AddForce(direita);

		}

		if ((Input.GetKeyUp(KeyCode.LeftArrow)) || (Input.GetKeyUp(KeyCode.RightArrow)))
		{
			rigidbody2D.velocity = Vector2.zero;

		}
		// Devagar se sair da pista
		//Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
		//if (screenPosition.y > Screen.height || screenPosition.y < 0)
		//{
		//Die();
		//}
	}

	// Update is called once per frame
	void OnGUI ()
	{
		GUI.color = Color.black;
		GUILayout.Label(" Dinheiro $$$: " + dinheiro.ToString());
	}

	// Colisao com moedas
	void OnCollisionEnter2D(Collision2D other)
	{
		if (other.gameObject.tag == "Coin")
		{
			dinheiro++;
			Destroy(other.gameObject);

		}
	}

	// Destroy everything that enters the trigger
	/*void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == "Coin")
{
dinheiro++;
Destroy(other.gameObject);

}
}*/

	//void Die()
	//{
	// Application.LoadLevel(Application.loadedLevel);
	//}
}

GENERATE

using UnityEngine;
using System.Collections;

public class Generate : MonoBehaviour
{
	public GameObject dindin;
	// Use this for initialization
	void Start()
	{
		InvokeRepeating("CreateObstacle", 1f, 1.5f);
	}
	void CreateObstacle()
	{
		Instantiate(dindin);

	}
}

DINHEIRO

using UnityEngine;
using System.Collections;

public class Dinheiro : MonoBehaviour {

	public Vector2 velocity = new Vector2(0, -4);
	public Vector3 velocity3D = new Vector3(0, -4, 0);
	public float range = 4;

	// Use this for initialization
	void Start () {

		//rigidbody2D.velocity = velocity;
		transform.position = new Vector3(transform.position.x – range * Random.value, transform.position.y , transform.position.z);

	}



	// Update is called once per frame
	void Update () {
		transform.position += velocity3D * Time.deltaTime;
	}

}

Leave a comment

Your email address will not be published. Required fields are marked *