Use keyboard W, A, S and D to move around
Unity Web Player |
Build 1.2
« created with
Unity
»
Download Unity Project files on Google Drive (.zip)
coinCollect.cs
using UnityEngine; using System.Collections; public class coinCollect : MonoBehaviour { // Script Reference public timerText timerText; // public int value; void OnTriggerEnter2D(Collider2D collidedObject) { if (collidedObject.tag == "Player") { collidedObject.GetComponent
().score += value; timerText.timer += 1; } } /* void OnTriggerEnter2D(Collider2D collidedObject) { if (collidedObject.tag == "Player") { collidedObject.GetComponent
().score += value; timerText.timer += 1; } }*/ }
coinCounter.cs
using UnityEngine; using System.Collections; public class CoinCounter : MonoBehaviour { public int score; public GUIText EggCount; public int maxEggs = 250; void Update (){ EggCount.text = "Eggs " + score + " / " + maxEggs; } }
MagnetMove.cs
using UnityEngine; using System.Collections; public class MagnetMove : MonoBehaviour { public Transform target; public float speed; void OnTriggerStay2D(Collider2D collidedObject) { if (collidedObject.tag == "Player") { float step = speed * Time.deltaTime; transform.position = Vector3.MoveTowards(transform.position, target.position, step); Destroy(gameObject,0.25f); } } }
timerText.cs
using UnityEngine; using System.Collections; public class timerText : MonoBehaviour { public GUIText timeText; // The countdown timer public float timer; // Update is called once per frame void Update () { timer -= Time.deltaTime; timeText.text = "Time " + timer.ToString ("0"); if (timer <= 0){ timeText.text = ""; Time.timeScale = 0; } } }
playerController.cs
using UnityEngine; using System.Collections; public class playerController : MonoBehaviour { public float speed; // MOVEMENT // void FixedUpdate () { float moveHorizontal = Input.GetAxis ("Horizontal"); float moveVertical = Input.GetAxis ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, moveVertical, 0.0f); rigidbody2D.velocity = movement * speed; //Right if (moveHorizontal >= 0.1) { transform.localScale = new Vector3(1,1,1); transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); } //Left if (moveHorizontal <= -0.1) { transform.localScale = new Vector3(-1,1,1); transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); } //Up if (moveVertical >= 0.1) { transform.localScale = new Vector3(1,1,1); transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); } //Down if (moveVertical <= -0.1) { transform.localScale = new Vector3(1,1,1); transform.rotation = Quaternion.Euler(new Vector3(0, 0, 0)); } // DIAGONAL ROTATE // if (Input.GetKey(KeyCode.A)) { Vector3 newRotation = transform.rotation.eulerAngles; newRotation.z += 10; transform.rotation = Quaternion.Euler (newRotation); } else if (Input.GetKey(KeyCode.D)) { Vector3 newRotation = transform.rotation.eulerAngles; newRotation.z -= 10; transform.rotation = Quaternion.Euler (newRotation); } } }