public Obstacle FindClosestObstacleForMissile(Vector3 startPosition, LevelObjectType type) { Obstacle closest = null; if (IsCurrentlyActive) { int total_count = transform.childCount; for (int i = 0; i < total_count; i++) { ObstacleBlock block = transform.GetChild(i).GetComponent <ObstacleBlock>(); if (block != null) { int total_obstacles = block.obstacles.Length; for (int j = 0; j < total_obstacles; j++) { if (block.obstacles[j].gameObject.activeSelf && block.obstacles[j].TypeOfObstacle == type && !SkillsHandler.CheckIfTargetExists(block.obstacles[j].UniqueID)) { closest = block.obstacles[j]; } } } } } return(closest); }
public void InitializeBlock(Action <CollectableType> _collectableCallback, int _distanceMarker, float _coinRotationOffset) { //initialize distanceMarker distanceText.text = "" + _distanceMarker; //initialize obstacles myObstacles.Clear(); for (int i = 0; i < obstacles.Count; i++) { if (obstacles[i] != ObstacleType.None) { ObstacleBlock newObstacle = ObstaclePooler.Instance.GetObstacle(obstacles[i]); newObstacle.SetLocation(ObstacleLocations[i]); newObstacle.Initialize(); myObstacles.Add(newObstacle); } } //initialize collectables myCollectables.Clear(); for (int i = 0; i < collectables.Count; i++) { if (collectables[i] != CollectableType.None) { Collectable newCollectable = CollectablePooler.Instance.GetCollectable(collectables[i]); newCollectable.SetLocation(collectableLocations[i]); newCollectable.Initialize(_collectableCallback, RemoveCollectable, _coinRotationOffset); myCollectables.Add(newCollectable); } } }
private void Start() { for (int i = 0; i < startAmount; i++) { ObstacleBlock newObstacle = (ObstacleBlock)Instantiate(pooledObstacle); pooledObstacles.Add(newObstacle); newObstacle.transform.SetParent(gameObject.transform); } }
public void HandleCollision(ObstacleBlock _obstacle) { if (_obstacle.MyObstacleType == ObstacleType.Barrier) { screenShake.Shake(); PlaySound(hitRockSound); if (shieldActive) { _obstacle.Destroyed(); if (OnShieldBreak != null) { OnShieldBreak(); } } else { GameOver(); } } else if (_obstacle.MyObstacleType == ObstacleType.Breakable && myCharacterState == CharacterState.Charging) { screenShake.Shake(); if (ParticleManager.Instance != null) { ParticleManager.Instance.CreateParticles(ParticleType.Hurdle, myTransform.position); } PlaySound(hitFenceSound); if (unlimitedChargePower) { myAnimator.SetTrigger("Ram"); } _obstacle.Destroyed(); } else { PlaySound(hitRockSound); screenShake.Shake(); if (shieldActive) { if (ParticleManager.Instance != null) { ParticleManager.Instance.CreateParticles(ParticleType.Hurdle, myTransform.position + Vector3.up); } _obstacle.Destroyed(); if (OnShieldBreak != null) { OnShieldBreak(); } } else { GameOver(); } } }
public ObstacleBlock GetPooledObstacle() { for (int i = 0; i < pooledObstacles.Count; i++) { if (!pooledObstacles[i].gameObject.activeInHierarchy) { return(pooledObstacles[i]); } } ObstacleBlock newObstacle = (ObstacleBlock)Instantiate(pooledObstacle); pooledObstacles.Add(newObstacle); newObstacle.transform.SetParent(gameObject.transform); return(newObstacle); }
public ObstacleBlock GetObstacle(ObstacleType _type) { ObstacleBlock obstacle = null; switch (_type) { case ObstacleType.Breakable: obstacle = breakableWalls.GetPooledObstacle(); break; case ObstacleType.Barrier: obstacle = barrierWalls.GetPooledObstacle(); break; default: Debug.LogError("Invalid Request to Obstalce Pooler"); break; } return(obstacle); }