Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Roll-a-ball workshop
- // PlayerController
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public Rigidbody rb;
- public float forceMultiplier = 5f;
- public float jumpForce = 100f;
- // Update is called once per frame
- void Update()
- {
- float horizontalInput = Input.GetAxis("Horizontal");
- float verticalInput = Input.GetAxis("Vertical");
- Vector3 direction = Vector3.right * horizontalInput + Vector3.forward * verticalInput;
- Vector3 force = direction * forceMultiplier;
- bool jumpInput = Input.GetKeyDown(KeyCode.Space);
- if (jumpInput)
- {
- force = force + Vector3.up * jumpForce;
- }
- rb.AddForce(force);
- }
- }
- // CoinCollector
- using UnityEngine;
- public class CoinCollector : MonoBehaviour
- {
- public int coinsCollected = 0;
- void OnTriggerEnter(Collider other)
- {
- other.gameObject.SetActive(false);
- coinsCollected += 1;
- }
- }
- // Spinner
- using UnityEngine;
- public class Spinner : MonoBehaviour
- {
- public Transform transform;
- public float speed = 90f;
- void Update()
- {
- Vector3 rotation = new Vector3(0f, 0f, speed * Time.deltaTime);
- transform.Rotate(rotation);
- }
- }
- // GameController
- using TMPro;
- using UnityEngine;
- public class GameController : MonoBehaviour
- {
- public CoinCollector collector;
- public int winningScore = 5;
- public TextMeshProUGUI scoreText;
- public TextMeshProUGUI completionText;
- void Update()
- {
- scoreText.text = $"{collector.coinsCollected}/{winningScore} collected";
- bool gameCompleted = collector.coinsCollected >= winningScore;
- completionText.gameObject.SetActive(gameCompleted);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement