Advertisement
lemansky

Untitled

Mar 26th, 2021
975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 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.     public void AddScore(int scoreToAdd)
  35.     {
  36.         score += scoreToAdd;
  37.         scoreText.text = "Score: " + score;
  38.     }
  39.  
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement