//Projectiles.cs
private void ApplyDebuff()
{
if(target.ElementType!=elementType)//๋™์ผ ์†์„ฑ ์•„๋‹๋•Œ ๋””๋ฒ„ํ”„๊ฐ€ ๊ฑธ๋ฆผ
{
float roll = Random.Range(0, 100);//๋””๋ฒ„ํ”„๊ฐ€ ๊ฑธ๋ฆด ํ™•๋ฅ 0~100
if(roll<=parent.Proc)//proc๋Š” ๋””๋ฒ„ํ”„ ํ™•๋ฅ , ํ™•๋ฅ  ๊ตด๋ ค์„œ proc ๋ฏธ๋งŒ์ด๋ฉด ๋””๋ฒ„ํ”„ ๊ฑธ๋ฆผ
{
target.AddDebuff(parent.GetDebuff());
}
}
}
//Debuff.cs
public abstract class Debuff //ํด๋ž˜์Šค์˜ ๋ชฉ์ ๊ณผ ๋™์ผํ•œ ํ•˜์œ„ ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค๋ ค๊ณ , ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ํ•˜์œ„ํด๋ž˜์Šค๋กœ ๋„ฃ์„๋• ์ถ”์ƒํด๋ž˜์Šค๋กœ ๋งŒ๋“ค์–ด์•ผํ•œ๋‹ค.
{
protected Monster target;
private float duration;
private float elapsed;//๊ฒฝ๊ณผ
public Debuff(Monster target, float duration)
{
this.target = target;
this.duration = duration;
}
public virtual void Update()
{
elapsed += Time.deltaTime;
if(elapsed>=duration)
{
Remove();
}
}
public virtual void Remove()
{
if (target !=null)
{
target.RemoveDebuff(this);
}
}
}
//FireDebuff.cs
//๋ฉ”์†Œ๋“œ:ํด๋ž˜์Šค,๊ตฌ์กฐ์ฒด ์—ด๊ฑฐํ˜•์— ํฌํ•จ๋˜์–ด์žˆ๋Š” ํ•จ์ˆ˜
//ํ•จ์ˆ˜: ํŠน์ • ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๋Š” ์ฝ”๋“œ ์กฐ๊ฐ์œผ๋กœ์จ ๋ฉ”์†Œ๋“œ๋ฅผ ํฌํ•จํ•จ
public class FireDebuff : Debuff
{
private float tickTime;
private float timeSinceTick;//Time duration
private float tickDamage;
public FireDebuff(float tickDamage, float tickTime, float duration ,Monster target):base(target,duration)//Debuff์—์„œ Debuff.debuffํ•จ์ˆ˜
{
this.tickDamage = tickDamage;
this.tickTime = tickTime;
}
public override void Update()
{
if(target!=null)
{
timeSinceTick += Time.deltaTime;//deltatime ์ „ ํ”„๋ ˆ์ž„์ด ์™„๋ฃŒ ๋˜๊ธฐ๊นŒ์ง€์˜ ์‹œ๊ฐ„,ํ•œ ํ”„๋ ˆ์ž„ ๋‹น ์‹คํ–‰ํ•˜๋Š” ์‹œ๊ฐ„,์ปดํ“จํ„ฐ ์„ฑ๋Šฅ์— ๋”ฐ๋ผ ์†๋„ ์ฐจ์ด๊ฐ€ ์žˆ๋Š”๊ฑฐ ๋ณด์ •
if(timeSinceTick>=tickTime)//tickTime์ด Time SinceTick๋ณด๋‹ค ํด ๊ฒฝ์šฐ์— ๋ฐ๋ฏธ์ง€๋ฅผ ์คŒ.
{
timeSinceTick = 0;
target.TakeDamage(tickDamage,Element.FIRE);//ํ‹ฑ๋‹น ๋ฐ๋ฏธ์ง€๋ฅผ ์คŒ.
}
}
target.TakeDamage(tickDamage, Element.FIRE);
base.Update();
}
}
//Monster.cs
public void TakeDamage(float damage, Element dmgSource)
{
if(IsActive)
{
Debug.Log(dmgSource);
if (dmgSource==ElementType)//๋งŒ์•ฝ ๊ณต๊ฒฉํ•˜๋Š” ํƒ€์ž…๊ณผ ํ”ผ๊ฒฉ๋ฐ›๋Š” ๋ชฌ์Šคํ„ฐ์˜ ๊ณต๊ฒฉ ํƒ€์ž…์ด ๊ฐ™๋‹ค๋ฉด ๋ฐ๋ฏธ์ง€ ๋ฐ˜๊ฐ
{
//Debug.Log(dmgSource);
damage = damage / resist;
//resist++;
}
health.CurrentVal -= damage;
if(health.CurrentVal<=0)
{
GameManager.Instance.Currency += 2;//๊ณจ๋“œ ํ†ตํ™” ์ถ”๊ฐ€
myAnimator.SetTrigger("Death");
IsActive = false;
GetComponent<SpriteRenderer>().sortingOrder--;//๋ ˆ์ด์–ด์˜ order๋ฅผ -ํ•œ๋‹ค๋Š” ๊ฒƒ. ์ฆ‰ ๋งต ๋’ค๋กœ ๊ฐ. ์ฃฝ๊ณ ๋‚˜๋ฉด ๋ ˆ์ด์–ด์˜ ์ˆœ๋ฒˆ์ด - ๋œ๋‹ค๋Š” ๊ฒƒ
}
}
}
//FireTower.cs
public class FireTower : Tower//ํƒ€์›Œ์—์„œ ์ƒ์†๋ฐ›์Œ. ์ผ๋ฐ˜์ ์œผ๋กœ๋Š” monobehaviour์—์„œ ์ƒ์†๋ฐ›์Œ
{
[SerializeField]
private float tickTime;
[SerializeField]
private float tickDamage;
public float TickTime
{
get
{
return tickTime;
}
}
public float TickDamage
{
get
{
return tickDamage;
}
}
private void Start()
{
ElementType = Element.FIRE;
}
public FireTower()
{
}
public override Debuff GetDebuff()
{
return new FireDebuff(TickDamage,TickTime,DebuffDuration,Target);
}
//Tower.cs
[SerializeField]
private int damage;
[SerializeField]
private float debuffDuration;
[SerializeField]
private float proc;//๊ฑธ๋ฆด ํ™•๋ฅ . 100์ด ์ตœ๋Œ€ 0์ด ์ตœ์†Œ.
public Element ElementType { get; protected set; }//ํ”„๋กœํ…ํ‹ฐ๋“œ set์€ ํ•˜์œ„ ํด๋ž˜์Šค์—์„œ๋งŒ ์‚ฌ์šฉ๊ฐ€๋Šฅ
public int Price { get; set; }//ํผ๋ธ”๋ฆญ ์ •์ˆ˜๋Š” get set์œผ๋กœ
public float ProjectileSpeed //์ด๋ ‡๊ฒŒ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ ๋Š” ๋‹ค๋ฅธ ์Šคํฌ๋ฆฝํŠธ์—์„œ๋„ ์‚ฌ์šฉํ•˜๊ฒŒ ํ•˜๊ธฐ์œ„ํ•ด์„œ
{
get { return projectileSpeed; }
}
public int Damage
{
get
{
return damage;
}
}
public float DebuffDuration
{
get
{
return debuffDuration;
}
set
{
this.debuffDuration = value;
}
}
public float Proc
{
get
{
return proc;
}
set
{
this.proc = value;
}
}

public์œผ๋กœ ์•ˆ์“ฐ๊ณ  ๊ตณ์ด get,set ์“ฐ๋Š”๊ฑด oop ์›์น™๋•Œ๋ฌธ์— ๊ทธ๋Ÿฐ๊ฑฐ๊ณ 

proc๋Š” ๋””๋ฒ„ํ”„ ๊ฑธ๋ฆดํ™•๋ฅ ์ž„
๋””๋ฒ„ํ”„ ๊ฑธ๋ฆดํ™•๋ฅ  100ํผ ์„ค์ •ํ•˜๊ณ , debuffDruatin=์ง€์†์‹œ๊ฐ„
์„ค์ •ํ–ˆ๊ณ , ๊ณต๊ฒฉ์„ ๋ฐ›์œผ๋ฉด
์ผ๋‹จ ํˆฌ์‚ฌ์ฒด ๋ฐ๋ฏธ์ง€ ์ž์ฒด๋Š” ๋ฐ›์Œ
๋ฌธ์ œ๋Š” ํˆฌ์‚ฌ์ฒด ๋ฐ๋ฏธ์ง€ ์ดํ›„์—, ํ™”์ƒ ์ƒํƒœ๋ฅผ ๋งŒ๋“ค์–ด์„œ ๋””๋ฒ„ํ”„๋ฅผ ๋งŒ๋“ค๋ ค๊ณ  ์ด๋ ‡๊ฒŒ ํ‹ฑ๋‹น ๋ฐ๋ฏธ์ง€๋ฅผ ์ž…๊ฒŒ ํ–ˆ๋‹จ ๋ง์ด์•ผ?

๊ทผ๋ฐ ํ‹ฑ๋‹น ๋ฐ๋ฏธ์ง€๋ฅผ ์•ˆ๋ฐ›์Œ.

๋ญ๊ฐ€ ์‹ค์ˆ˜์ผ๊นŒ?


์ผ๋‹จ ๊ด€๋ จ๋œ ์ฝ”๋“œ๋“ค ๋‹ค ๊ฐ€์ง€๊ณ ์˜ด.