게임 플레이 추가 작업까지 진행된 소스
using UnityEngine;
using System.Collections;
public class EnemyRanged : Enemy {
public GameObject shotObj;
public Transform firePosition;
public float fireSpeed = 3;
GameObjectPool objPool;
Vector3 spawnPos = new Vector3(0, 50, 0);
GameObject tempObj;
Vector2 tempVector2 = new Vector2();
public override void Attack()
{
if( spawnPos.x == 0)
{
spawnPos += GameData.Instance.gamePlayManager
.gameObjectPoolPosition.transform.position;
}
if(objPool == null)
{
objPool = new GameObjectPool(
spawnPos.x,
shotObj);
}
EnemyShotObj tempEnemyShot = null;
if( !objPool.NextGameObject(out tempObj) )
{
tempObj = Instantiate(
shotObj,
spawnPos,
Quaternion.identity
) as GameObject;
tempObj.name = shotObj.name + objPool.lastIndex;
objPool.AddGameObject(tempObj);
tempEnemyShot = tempObj.GetComponent<EnemyShotObj>();
tempEnemyShot.InitReturnPosition(spawnPos);
}
tempObj.transform.position = firePosition.position;
tempVector2 = Vector2.right* -1 * fireSpeed;
tempObj.rigidbody2D.velocity = tempVector2;
if(tempEnemyShot == null)
{
tempEnemyShot = tempObj.GetComponent<EnemyShotObj>();
}
tempEnemyShot.InitShotObj( attackPower );
tempEnemyShot.TurnOnTrigger();
}
public void CallAttack()
{
Attack();
}
}