Advertisement
CakeMeister

UFO player phan5

Jul 18th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Player : MonoBehaviour
  7. {
  8.  
  9.     public Rigidbody2D r2;
  10.     public Vector2 direction;
  11.     public float speed = 3f;
  12.  
  13.     public int score = 0;
  14.  
  15.     public Text scoretext;
  16.     public Text wintext;
  17.  
  18.     // Use this for initialization
  19.     void Start()
  20.     {
  21.         setscoretext();
  22.         r2 = GetComponent<Rigidbody2D>();
  23.         wintext.text = "";
  24.     }
  25.  
  26.  
  27.     // Update is called once per frame
  28.     void Update()
  29.     {
  30.         float h = Input.GetAxis("Horizontal");
  31.         float v = Input.GetAxis("Vertical");
  32.         direction.x = h;
  33.         direction.y = v;
  34.  
  35.         r2.AddForce(direction * speed);
  36.  
  37.         if (score >= 6)
  38.             wintext.text = "YOU WIN !!";
  39.     }
  40.  
  41.     private void OnTriggerEnter2D(Collider2D col)
  42.     {
  43.         if (col.CompareTag("coins"))
  44.         {
  45.             score += 1;
  46.             col.gameObject.SetActive(false);
  47.             setscoretext();
  48.         }
  49.     }
  50.  
  51.     void setscoretext()
  52.     {
  53.         scoretext.text = "Score: " + score.ToString();
  54.  
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement