Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////Item script//////////////////////////////////////
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Item
- {
- public string Name = "None";
- public string Description = "Please add description";
- //Using an array allows the item to be used on any amount of targers, including 0, 1 and 10000
- GameObject[] Targets;
- //The effect is a abstract class
- public ItemEffect Effect = null;
- public Item(string NewName, string NewDescription , ItemEffect NewEffect)
- {
- Name = NewName;
- Description = NewDescription;
- Effect = NewEffect;
- }
- public void OnUse()
- {
- Effect.Use(Targets);
- }
- }
- ////////Item Effect//////////////////////////////////////
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public abstract class ItemEffect
- {
- public abstract void Use(GameObject[] Targets);
- };
- //The All items class is just to keep things organized
- public class AllItemEffects
- {
- public class HealingTargets : ItemEffect
- {
- int Healing = 20;
- public HealingTargets(int Amount)
- {
- Healing = Amount;
- }
- public override void Use(GameObject[] Targets)
- {
- foreach (GameObject Target in Targets)
- {
- Target.GetComponent<DudHealthSystem>().ChangeHealth(Healing);
- }
- }
- }
- public class DamageTargets : ItemEffect
- {
- int Damage = 20;
- public DamageTargets(int Amount)
- {
- Damage = Amount;
- }
- public override void Use(GameObject[] Targets)
- {
- foreach (GameObject Target in Targets)
- {
- Target.GetComponent<DudHealthSystem>().ChangeHealth(-Damage);
- }
- }
- }
- }
- ////////Dud Health System//////////////////////////////////////
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class DudHealthSystem : MonoBehaviour
- {
- //Just a placeholder health system
- int MaxHP = 100;
- int HP = 100;
- public void ChangeHealth(int Amount)
- {
- HP = Mathf.Clamp(HP + Amount, 0, MaxHP);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement