Unity Learn home
0
2
roll a ball
26 views
basic roll a ball game
Media
1
1
TARIK_PISIREN
a month ago
using UnityEngine.InputSystem; using UnityEngine; using UnityEditor; using TMPro; public class PlayerController : MonoBehaviour { [SerializeField] private TextMeshProUGUI countText; [SerializeField] private TextMeshProUGUI endGameText; private Rigidbody rb; private float movementX; private float movementY; private int count; [SerializeField] private float speed; void Awake() { rb = GetComponent<Rigidbody>(); } void Start() { count = 0; SetCountText(); endGameText.gameObject.SetActive(false); } void FixedUpdate() { Vector3 movementDirection = new Vector3(movementX, 0.0f, movementY); rb.AddForce(movementDirection * speed, ForceMode.Impulse); } void SetCountText() { if (count >= 12) { endGameText.gameObject.SetActive(true); countText.gameObject.SetActive(false); Destroy(GameObject.FindWithTag("Enemy")); } else { countText.text = "Count: " + count.ToString(); } } void OnMove(InputValue movementValue) { // oyuncunun verdiği giriş dedğerlerini alıp movementVector variable da saklar. Vector2 movementVector = movementValue.Get<Vector2>(); movementX = movementVector.x; movementY = movementVector.y; } void OnTriggerEnter(Collider other) { if (other.CompareTag("Collectible")) { other.gameObject.SetActive(false); count += 1; SetCountText(); } } void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Enemy")) { Destroy(gameObject); endGameText.gameObject.SetActive(true); endGameText.text = "You Lose!"; } } } like this?
F
FastRun
a month ago
(edited)
Can you give me the PlayerControls.cs?