/// <summary> /// spawns then determines next spawn position /// </summary> /// <param name="spawnPosition">Spawn position.</param> protected virtual void DistanceObjectSpawn(Vector3 spawnPos) { //spawn object at position parsed GameObject spawnedGameObject = spawn(spawnPos, false); //if no spawnobject is present in hirarchy then do a fresh spawn if (spawnedGameObject == null) { lastSpawnedTransform = null; NextSpawnDistance = UnityEngine.Random.Range(MinGap.x, MaxGap.x); return; } //checks for pool script attached to object if (spawnedGameObject.GetComponent <PoolableGameObject> () == null) { throw new Exception(gameObject.name + " No PoolableGameObject Present"); } //if theres a moving script attached rotate towards needed movement if (ObjectRotatedToSpawnDirection) { spawnedGameObject.transform.rotation *= transform.rotation; } //if this is a moveingobject then move in the specified direction if (spawnedGameObject.GetComponent <MovingGameObject> () != null) { spawnedGameObject.GetComponent <MovingGameObject> ().Direction = transform.rotation * Vector3.left; } // if (lastSpawnedTransform != null) { //center object posision to spawners poisiton spawnedGameObject.transform.position = transform.position; //get relative X distance between spawner and object float XDistanceBetweenSpawnerAndGameObject = transform.InverseTransformPoint(lastSpawnedTransform.position).x; //new object is aligned with the previous one //taking into acount the witdh of both objects spawnedGameObject.transform.position += transform.rotation * Vector3.right * (XDistanceBetweenSpawnerAndGameObject + lastSpawnedTransform.GetComponent <PoolableGameObject> ().Size.x / 2 + spawnedGameObject.GetComponent <PoolableGameObject> ().Size.x / 2); //based on the values defined in the inspector clamp gap to object spawnedGameObject.transform.position += (transform.rotation * ClampedPosition(MiscTools.RandomVector3(MinGap, MaxGap) / 2)); //if spawned object is a mooving object, tell it to move if (spawnedGameObject.GetComponent <MovingGameObject> () != null) { spawnedGameObject.GetComponent <MovingGameObject> ().Move(); } } //tell object its spawning is finished spawnedGameObject.GetComponent <PoolableGameObject>().TriggerOnSpawnFinished(); //decide when we should try spawning next object NextSpawnDistance = spawnedGameObject.GetComponent <PoolableGameObject>().Size.x / 2; //store spawned object, which will be used for next spawn lastSpawnedTransform = spawnedGameObject.transform; }
/// <summary> /// On every frame fill the bar according to delta time * progressbarspeed /// </summary> protected virtual void Update() { LoadingProgressBar.GetComponent <Image> ().fillAmount = MiscTools.MoveFromTo(LoadingProgressBar.GetComponent <Image> ().fillAmount, filltarget, Time.deltaTime * ProgressBarSpeed); }