새로운 적 캐릭터 추가까지 진행된 소스코드
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(objPool == null)
{
objPool = new GameObjectPool(
GameData.Instance.gamePlayManager
.gameObjectPoolPosition.transform.position.x,
shotObj);
}
if( !objPool.NextGameObject(out tempObj) )
{
tempObj = Instantiate(
shotObj,
GameData.Instance.gamePlayManager
.gameObjectPoolPosition.transform.position,
Quaternion.identity
) as GameObject;
tempObj.name = shotObj.name + objPool.lastIndex;
objPool.AddGameObject(tempObj);
}
tempObj.transform.position = firePosition.position;
tempVector2 = Vector2.right* -1 * fireSpeed;
tempObj.rigidbody2D.velocity = tempVector2;
EnemyShotObj tempEnemyShot = tempObj.GetComponent<EnemyShotObj>();
tempEnemyShot.InitShotObj( attackPower );
}
public void CallAttack()
{
Attack();
}
}