게임 플레이 추가 작업까지 진행된 소스
using UnityEngine;
using System.Collections;
public class ShotObj : MonoBehaviour {
protected float attackPower = 1;
protected Vector3 initPos;
protected bool isWork = false;
public void InitShotObj(float setupAttackPower)
{
attackPower = setupAttackPower;
}
void OnTriggerEnter2D(Collider2D other)
{
if(!isWork) return;
if (other.CompareTag("enemy") || other.CompareTag("boss"))
{
AttackAndDestroy(other);
}
else if (other.CompareTag("invisibleArea"))
{
ResetShotObj();
}
}
protected void AttackAndDestroy(Collider2D other)
{
IDamageable damageTarget =
(IDamageable)other.GetComponent(typeof(IDamageable));
damageTarget.Damage(attackPower);
ResetShotObj();
}
public void InitReturnPosition(Vector3 setupInitPos)
{
initPos = setupInitPos;
}
public void TurnOnTrigger()
{
isWork = true;
}
public void ResetShotObj()
{
transform.position = initPos;
isWork = false;
rigidbody2D.velocity = Vector3.zero;
}
}