Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class CollisionScript : MonoBehaviour {
- public int scorePoints;
- public int healthAmount;
- public Text scoreUI;
- public Text health;
- public GameObject points;
- public GameObject player;
- public Camera mainCamera;
- public GameObject obstacle;
- public GameObject obstacle1;
- Vector3 randomPos;
- Vector3 randomPos2;
- Vector3 randomPos3;
- float speed = 1.0f;
- float obstacleSpeedX = 1.5f;
- float obstacleSpeedY = 1.5f;
- public void RandomFunction() {
- float screenX = Random.Range(2.0f, mainCamera.pixelWidth - 2.0f);
- float screenY = Random.Range(2.0f, mainCamera.pixelHeight - 2.0f);
- float screenZ = 10.0f;
- Vector3 position = mainCamera.ScreenToWorldPoint(new Vector3(screenX, screenY, screenZ));
- float screenX2 = Random.Range(4.0f, mainCamera.pixelWidth - 4.0f);
- float screenY2 = Random.Range(4.0f, mainCamera.pixelHeight - 4.0f);
- float screenZ2 = 10.0f;
- Vector3 position2 = mainCamera.ScreenToWorldPoint(new Vector3(screenX2, screenY2, screenZ2));
- float screenX3 = Random.Range(4.0f, mainCamera.pixelWidth - 4.0f);
- float screenY3 = Random.Range(4.0f, mainCamera.pixelHeight - 4.0f);
- float screenZ3 = 10.0f;
- Vector3 position3 = mainCamera.ScreenToWorldPoint(new Vector3(screenX3, screenY3, screenZ3));
- randomPos2 = position2;
- if (scorePoints == 1) {
- randomPos = position;
- randomPos3 = position3;
- }
- }
- void Start() {
- obstacle.SetActive (false);
- obstacle1.SetActive (false);
- }
- void Update() {
- if (scorePoints == 5) {
- obstacle.SetActive (true);
- obstacle.transform.position = randomPos;
- } else if (scorePoints == 10) {
- obstacle1.SetActive (true);
- obstacle1.transform.position = randomPos3;
- } else if (scorePoints >= 15) {
- obstacle.transform.position += Vector3.right * obstacleSpeedX * Time.deltaTime;
- obstacle1.transform.position += Vector3.up * obstacleSpeedY * Time.deltaTime;
- }
- if (obstacle.transform.position.x <= -8.9f) {
- obstacleSpeedX = 1.5f;
- }
- if (obstacle.transform.position.x >= 8.9f) {
- obstacleSpeedX = -1.5f;
- }
- if (obstacle1.transform.position.y <= -5.0f) {
- obstacleSpeedY = 1.5f;
- }
- if (obstacle1.transform.position.y >= 5.0f) {
- obstacleSpeedY = -1.5f;
- }
- }
- public void pointPosition() {
- points.transform.position = randomPos2;
- }
- }
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- public class LethalCollisionScript : CollisionScript {
- void OnTriggerEnter2D(Collider2D coll) {
- healthAmount -= 1;
- player.transform.position = new Vector3(0,0,0);
- if (healthAmount >= 0) {
- health.text = "HEALTH: " + healthAmount;
- }
- if (healthAmount <= -1) {
- Application.LoadLevel (0);
- }
- }
- }
- using UnityEngine;
- using System.Collections;
- public class ObstacleScript : MonoBehaviour {
- // Update is called once per frame
- void Update () {
- transform.Rotate (new Vector3 (0, 0, 90) * Time.deltaTime * 2);
- }
- }
- using UnityEngine;
- using System.Collections;
- public class PlayerScript : MonoBehaviour {
- public float speed = 1.0f;
- public Camera mainCameraPS;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetKey (KeyCode.LeftArrow)) {
- transform.position += Vector3.left * speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.RightArrow)) {
- transform.position += Vector3.right * speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.UpArrow)) {
- transform.position += Vector3.up * speed * Time.deltaTime;
- }
- if (Input.GetKey (KeyCode.DownArrow)) {
- transform.position += Vector3.down * speed * Time.deltaTime;
- }
- if (transform.position.x <= -8.4f)
- transform.position = new Vector3 (-8.4f, transform.position.y, transform.position.z);
- else if (transform.position.x >= 8.4f)
- transform.position = new Vector3(8.4f, transform.position.y, transform.position.z);
- if (transform.position.y <= -4.6f)
- transform.position = new Vector3 (transform.position.x, -4.6f, transform.position.z);
- else if (transform.position.y >= 4.6f)
- transform.position = new Vector3 (transform.position.x, 4.6f, transform.position.z);
- }
- }
- using UnityEngine;
- using System.Collections;
- public class PointCollisionScript : CollisionScript {
- void OnTriggerEnter2D(Collider2D coll) {
- RandomFunction ();
- pointPosition ();
- scorePoints += 1;
- scoreUI.text = "SCORE: " + scorePoints.ToString ();
- }
- }
- public class GameController : MonoBehaviour
- {
- public GameObject Player;
- public UIManager UIManager;
- void Awake()
- {
- Player = GameObject.FindWithTag("Player");
- UIManager = GameObject.FindObjectOfType<UIManager>();
- }
- }
- public class Some_of_Game_Scripts : MonoBehaviour
- {
- GameController gameController;
- UIManager uiManager;
- void Start()
- {
- gameController = GameObject.FindWithTag("GameController");
- uiManager = gameController.UIManager;
- }
- void Update()
- {
- uiManager.SetStatusText_Or_Something("Some text");
- if (something)
- gameController.ResetGame();
- }
- }
Add Comment
Please, Sign In to add comment