Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class Player : MonoBehaviour
- {
- public Rigidbody2D r2;
- public Vector2 direction;
- public float speed = 3f;
- public int score = 0;
- public Text scoretext;
- public Text wintext;
- // Use this for initialization
- void Start()
- {
- setscoretext();
- r2 = GetComponent<Rigidbody2D>();
- wintext.text = "";
- }
- // Update is called once per frame
- void Update()
- {
- float h = Input.GetAxis("Horizontal");
- float v = Input.GetAxis("Vertical");
- direction.x = h;
- direction.y = v;
- r2.AddForce(direction * speed);
- if (score >= 6)
- wintext.text = "YOU WIN !!";
- }
- private void OnTriggerEnter2D(Collider2D col)
- {
- if (col.CompareTag("coins"))
- {
- score += 1;
- col.gameObject.SetActive(false);
- setscoretext();
- }
- }
- void setscoretext()
- {
- scoretext.text = "Score: " + score.ToString();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement