void CreateGameObject(GameObject targetObj, int amount, Transform parent, Vector3 localScale = default(Vector3)) { // 게임 오브젝트 풀 생성. GameObjectPool tempGameObjectPool = new GameObjectPool(gameObjectPoolPosition.transform.position.x, targetObj); for (int j = 0; j < amount; j++) { // 게임 오브젝트 생성. GameObject tempObj = Instantiate( targetObj, gameObjectPoolPosition.position, Quaternion.identity ) as GameObject; tempObj.name = targetObj.name + j; tempObj.transform.parent = parent; if (localScale != Vector3.zero) { tempObj.transform.localScale = localScale; } // 게임 오브젝트를 게임 오브젝트 풀에 등록. tempGameObjectPool.AddGameObject(tempObj); } gameObjectPools.Add(targetObj.name, tempGameObjectPool); }
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); }
// 게임 오브젝트 풀 초기화. void InitGameObjectPool() { spawnPos += GameData.Instance.gamePlayManager .gameObjectPoolPosition.transform.position; //원거리에서 공격할 수 있도록 구현. objPool = new GameObjectPool( spawnPos.x, tempObj); // 발사 오브젝트 생성. for (int i = 0; i < 20; ++i) { shotObjScript = null; GameObject makeObj = Instantiate( fireObj, spawnPos, Quaternion.Euler(Vector3.up * 90) ) as GameObject; makeObj.name = makeObj.name + i; objPool.AddGameObject(makeObj); shotObjScript = makeObj.GetComponent <ShotObj>(); shotObjScript.InitReturnPosition(spawnPos); } }
/// <summary> /// 创建一个实体 /// </summary> /// <param name="type">实体类型 1:GameObject;2:UI</param> /// <param name="assetName">资源名称</param> /// <param name="onCreateGameObject">创建成功回调</param> /// <returns></returns> public static int CreateGameObjectAsync(int type, string assetName, GameObjectPool.OnCreateGameObject onCreateGameObject) { int requestId = CreateAssetAsync(assetName, (Object tAsset, int tRequestId) => { int instanceId = GameObjectPool.AddGameObject(type, assetName, tAsset); onCreateGameObject(instanceId, tRequestId); }); return(requestId); }
void Fire(Vector3 inputPosition) { // 입력 위치(inputPosition)를 카메라가 바라보는 영역 안의 월드 좌표(절대 좌표)로 변환. tempVector3 = mainCamera.ScreenToWorldPoint(inputPosition); tempVector3.z = 0; // 벡터의 뺄셈 후 방향만 지닌 단위 벡터로 변경. fireDirection = tempVector3 - firePoint.position; fireDirection = fireDirection.normalized; // 발사할 오브젝트. shotObjScript = null; if (!objPool.NextGameObject(out tempObj)) { tempObj = Instantiate( fireObj, spawnPos, Quaternion.Euler(Vector3.up * 90) ) as GameObject; tempObj.name = tempObj.name + objPool.lastIndex; objPool.AddGameObject(tempObj); shotObjScript = tempObj.GetComponent <ShotObj>(); shotObjScript.InitReturnPosition(spawnPos); } if (shotObjScript == null) { shotObjScript = tempObj.GetComponent <ShotObj>(); } tempObj.transform.position = firePoint.position; // 발사한 오브젝트 속도 계산. tempVector2.Set(fireDirection.x, fireDirection.y); tempVector2 = tempVector2 * fireSpeed; // 속도 적용. tempObj.rigidbody2D.velocity = tempVector2; // 공격력을 전달한다. if (attDamage == 0) { attDamage = 1 + GameData.Instance.ConvertUpgradeLvToAddValue( GameData.Instance.userdata.attLv); } shotObjScript.InitShotObj(attDamage); shotObjScript.TurnOnTrigger(); }
// Update is called once per frame void Update() { currentDelayBetweenJumps += Time.deltaTime; if (isGround && delayBetweenJumps <= currentDelayBetweenJumps) { physicsBody.AddForce(Vector3.up * jumpPower * physicsBody.gravityScale * 100f); currentDelayBetweenJumps = 0; } if (transform.position.x > -1.3f) { passedPlayer = false; scoreGiven = false; } else { passedPlayer = true; } if (passedPlayer && !scoreGiven) { GameController.gameScore++; scoreGiven = true; jumpCompletedAudio.Play(); } transform.Translate(Vector3.left * moveSpeed / 100f * Time.timeScale); if (transform.position.x <= -8f) { enemyPool.AddGameObject(gameObject); } if (GameController.isPaused) { enemyAnimator.updateMode = AnimatorUpdateMode.Normal; } else { enemyAnimator.updateMode = AnimatorUpdateMode.UnscaledTime; } enemyAnimator.SetBool("isGround", isGround); }
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); } // position move 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(); }
// 적 캐릭터 별로 20개씩 게임 오브젝트를 생성하여 게임 오브젝트 풀에 등록한다. void InitGameObjectPools() { for (int i = 0; i < spawnEnemyObjs.Count; i++) { // 게임 오브젝트 풀 생성. GameObjectPool tempGameObjectPool = new GameObjectPool(gameObjectPoolPosition.transform.position.x, spawnEnemyObjs[i]); for (int j = 0; j < 20; j++) { // 게임 오브젝트 생성. GameObject tempEnemyObj = Instantiate( spawnEnemyObjs[i], gameObjectPoolPosition.position, Quaternion.identity ) as GameObject; tempEnemyObj.name = spawnEnemyObjs[i].name + j; tempEnemyObj.transform.parent = gameObjectPoolPosition; // 게임 오브젝트를 게임 오브젝트 풀에 등록. tempGameObjectPool.AddGameObject(tempEnemyObj); } gameObjectPools.Add(spawnEnemyObjs[i].name, tempGameObjectPool); } }
private void AddToLaserPool() { laserPool.AddGameObject(gameObject); }
// 게임 오브젝트 풀 초기화. void InitGameObjectPool() { spawnPos += GameData.Instance.gamePlayManager .gameObjectPoolPosition.transform.position; //원거리에서 공격할 수 있도록 구현. objPool = new GameObjectPool( spawnPos.x, tempObj); // 발사 오브젝트 생성. for(int i=0;i<20;++i) { shotObjScript = null; GameObject makeObj = Instantiate( fireObj, spawnPos, Quaternion.Euler(Vector3.up * 90) ) as GameObject; makeObj.name = makeObj.name + i; objPool.AddGameObject(makeObj); shotObjScript = makeObj.GetComponent<ShotObj>(); shotObjScript.InitReturnPosition(spawnPos); } }
void CreateGameObject(GameObject targetObj, int amount, Transform parent, Vector3 localScale=default(Vector3)) { // 게임 오브젝트 풀 생성. GameObjectPool tempGameObjectPool = new GameObjectPool(gameObjectPoolPosition.transform.position.x, targetObj); for (int j=0; j<amount; j++) { // 게임 오브젝트 생성. GameObject tempObj = Instantiate( targetObj, gameObjectPoolPosition.position, Quaternion.identity ) as GameObject; tempObj.name = targetObj.name + j; tempObj.transform.parent = parent; if (localScale != Vector3.zero) { tempObj.transform.localScale = localScale; } // 게임 오브젝트를 게임 오브젝트 풀에 등록. tempGameObjectPool.AddGameObject(tempObj); } gameObjectPools.Add(targetObj.name, tempGameObjectPool); }