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 move : MonoBehaviour
- {
- public string startmsg = "Peli alkaa";
- public int spd = 69;
- public Rigidbody rb;
- private int Score = 0;
- public float turnspd;
- private GameObject canvas;
- private Text text;
- // Start is called before the first frame update
- void Start()
- {
- Debug.Log("Testi");
- canvas = GameObject.Find("Canvas");
- text = canvas.GetComponent<Text>();
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetKey(KeyCode.LeftArrow)) { transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - turnspd, transform.rotation.eulerAngles.z); }
- if (Input.GetKey(KeyCode.DownArrow)) { rb.AddRelativeForce(Vector3.back * spd); }
- if (Input.GetKey(KeyCode.RightArrow)) { transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + turnspd, transform.rotation.eulerAngles.z); }
- if (Input.GetKey(KeyCode.UpArrow)) { rb.AddRelativeForce(Vector3.forward * spd); }
- }
- private void OnCollisionEnter(Collision collision)
- {
- if(collision.gameObject.tag == "Coin")
- {
- Score++;
- Destroy(collision.gameObject);
- text.text = "Coins: " + Score;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement