CakeMeister

UFO player phan 6

Jul 18th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 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 = 100f;
  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.normalized * speed)*Time.deltaTime/0.5f);
  36.  
  37.      
  38.  
  39.         if (score >= 6)
  40.             wintext.text = "YOU WIN !!";
  41.     }
  42.  
  43.     private void OnTriggerEnter2D(Collider2D col)
  44.     {
  45.         if (col.CompareTag("coins"))
  46.         {
  47.             score += 1;
  48.             col.gameObject.SetActive(false);
  49.             setscoretext();
  50.         }
  51.     }
  52.  
  53.     void setscoretext()
  54.     {
  55.         scoretext.text = "Score: " + score.ToString();
  56.  
  57.     }
  58. }
Add Comment
Please, Sign In to add comment