Advertisement
CakeMeister

UFO player phan3

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