Untitled
unknown
plain_text
2 months ago
7.7 kB
1
Indexable
using System.Collections; using UnityEngine; public class Player : MonoBehaviour { public int health = 100; public int mana = 50; public int level = 1; public int exp = 0; public float attackSpeed = 1f; public float moveSpeed = 5f; // Add skills here public Skill[] skills; void Update() { HandleMovement(); HandleCombat(); } void HandleMovement() { float moveX = Input.GetAxis("Horizontal"); float moveY = Input.GetAxis("Vertical"); transform.Translate(new Vector3(moveX, 0, moveY) * moveSpeed * Time.deltaTime); } void HandleCombat() { if (Input.GetKeyDown(KeyCode.Space)) { Attack(); } if (Input.GetKeyDown(KeyCode.Alpha1)) // Example skill trigger { UseSkill(0); // Skill index } } void Attack() { // Basic attack logic here Debug.Log("Player attacks!"); } void UseSkill(int skillIndex) { if (skills[skillIndex].manaCost <= mana) { mana -= skills[skillIndex].manaCost; Debug.Log($"Used {skills[skillIndex].name} skill!"); } else { Debug.Log("Not enough mana!"); } } public void GainExp(int amount) { exp += amount; if (exp >= 100) // Level up condition { LevelUp(); } } void LevelUp() { level++; exp = 0; health += 10; // Increase health on level up mana += 5; // Increase mana on level up Debug.Log("Level Up!"); } } [System.Serializable] public class Skill { public string name; public int manaCost; public float cooldown; public string description; } } } } } } } } } } } } } } }
Editor is loading...
Leave a Comment