Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using TMPro;
- public class PlayerController : MonoBehaviour
- {
- public float speed = 10.0f;
- Rigidbody rb;
- [SerializeField]
- private Vector3 movement;
- private int points = 0;
- TextMeshPro scoreText;
- TextMeshPro winText;
- private bool finish = false;
- public GameObject newCollectable;
- void Start()
- {
- rb = this.GetComponent<Rigidbody>();
- scoreText = GameObject.Find("Score").GetComponent<TextMeshPro>();
- winText = GameObject.Find("Win").GetComponent<TextMeshPro>();
- winText.gameObject.SetActive(false);
- }
- void Update()
- {
- if (!finish)
- {
- movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
- }
- //transform.Translate(movement * speed * Time.deltaTime);
- }
- private void FixedUpdate()
- {
- //rb.AddForce(movement * speed);
- //rb.velocity = movement * speed;
- rb.MovePosition(transform.position + (movement * speed * Time.deltaTime));
- }
- private void OnTriggerEnter(Collider other)
- {
- if (other.gameObject.CompareTag("Pickup"))
- {
- other.gameObject.SetActive(false);
- points += other.gameObject.GetComponent<Bonus>().Point;
- scoreText.text = $"Score: {points}";
- if (points >= 20)
- {
- winText.gameObject.SetActive(true);
- finish = true;
- }
- else if (points >= 6)
- {
- Instantiate(newCollectable, new Vector3(Random.Range(-4.0f, 4.0f), 1.5f, Random.Range(-4.0f, 4.0f)), transform.rotation);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement