public class PlayerController : BasePlayer { public float moveSpeed = 10f; protected override void Update() { base.Update(); // Move the player in the direction of input float horizontalInput = Input.GetAxis("Horizontal"); float verticalInput = Input.GetAxis("Vertical"); transform.Translate(new Vector3(horizontalInput, 0, verticalInput) * moveSpeed * Time.deltaTime); } }
public class PlayerController : BasePlayer { public int maxHealth = 100; private int currentHealth; private void Start() { currentHealth = maxHealth; } public void TakeDamage(int damageAmount) { currentHealth -= damageAmount; if (currentHealth <= 0) { Die(); } } private void Die() { // Handle player death logic here } }In this example, we also inherit from BasePlayer to create our own player controller. We declare variables for the player's maximum health and their current health, and we use the TakeDamage() method to subtract health from the player when they take damage. If the player's health reaches 0 or below, we call the Die() method to handle the player's death. Package/library: Unity Engine.