Advertisement
lemansky

Untitled

Mar 26th, 2021
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TMPro;
  5.  
  6. public class PlayerController : MonoBehaviour
  7. {
  8.     public float speed = 10.0f;
  9.     Rigidbody rb;
  10.     [SerializeField]
  11.     private Vector3 movement;
  12.  
  13.     TextMeshProUGUI scoreText;
  14.     int score = 0;
  15.     void Start()
  16.     {
  17.         rb = this.GetComponent<Rigidbody>();
  18.         scoreText = GameObject.Find("ScoreText").GetComponent<TextMeshProUGUI>();
  19.     }
  20.  
  21.     void Update()
  22.     {
  23.         movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
  24.         //transform.Translate(movement * speed * Time.deltaTime);
  25.     }
  26.  
  27.     private void FixedUpdate()
  28.     {
  29.         //rb.AddForce(movement * speed);
  30.         //rb.velocity = movement * speed;
  31.         rb.MovePosition(transform.position + (movement * speed * Time.deltaTime));
  32.     }
  33.  
  34.     private void OnTriggerEnter(Collider other)
  35.     {
  36.         if (other.gameObject.CompareTag("PickUp"))
  37.         {
  38.             //other.gameObject.SetActive(false);
  39.             Destroy(other.gameObject);
  40.             score++;
  41.             scoreText.text = "Score: " + score;
  42.         }
  43.     }
  44.  
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement