Advertisement
Guest User

unity

a guest
Nov 21st, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class move : MonoBehaviour
  7. {
  8. public string startmsg = "Peli alkaa";
  9. public int spd = 69;
  10. public Rigidbody rb;
  11. private int Score = 0;
  12. public float turnspd;
  13. private GameObject canvas;
  14. private Text text;
  15. // Start is called before the first frame update
  16. void Start()
  17. {
  18. Debug.Log("Testi");
  19. canvas = GameObject.Find("Canvas");
  20. text = canvas.GetComponent<Text>();
  21. }
  22.  
  23. // Update is called once per frame
  24. void Update()
  25. {
  26. if (Input.GetKey(KeyCode.LeftArrow)) { transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y - turnspd, transform.rotation.eulerAngles.z); }
  27. if (Input.GetKey(KeyCode.DownArrow)) { rb.AddRelativeForce(Vector3.back * spd); }
  28. if (Input.GetKey(KeyCode.RightArrow)) { transform.rotation = Quaternion.Euler(transform.rotation.eulerAngles.x, transform.rotation.eulerAngles.y + turnspd, transform.rotation.eulerAngles.z); }
  29. if (Input.GetKey(KeyCode.UpArrow)) { rb.AddRelativeForce(Vector3.forward * spd); }
  30. }
  31.  
  32. private void OnCollisionEnter(Collision collision)
  33. {
  34. if(collision.gameObject.tag == "Coin")
  35. {
  36. Score++;
  37. Destroy(collision.gameObject);
  38. text.text = "Coins: " + Score;
  39. }
  40. }
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement