Example #1
0
        public int AddFirefly(bool destroyOnReachTarget, Vector3 spawnPoint, Transform target = null)
        {
            if (target == null)
            {
                target = GetRandomTransformPoint();
            }

            if (ExtensionFunctions.IsVectorZero(spawnPoint))
            {
                spawnPoint = GetRandomTransformPoint().position;
            }

            _currentIndex += 1;

            GameObject         fireflyInstance    = SpawnFirefly(spawnPoint);
            FloatyFollowTarget followTarget       = fireflyInstance.GetComponent <FloatyFollowTarget>();
            FireflyInformation fireflyInformation = new FireflyInformation
            {
                destroyOnReachTarget = destroyOnReachTarget,
                fireflyIndex         = _currentIndex,
                fireflyInstance      = followTarget
            };

            followTarget.UpdateTarget(target);
            _fireflies.Add(fireflyInformation);

            return(_currentIndex);
        }
Example #2
0
        public void UpdateFireflyTarget(Transform target, int fireflyIndex)
        {
            FireflyInformation fireflyInformation = _fireflies.FirstOrDefault(_ => _.fireflyIndex == fireflyIndex);

            if (fireflyInformation == null)
            {
                Debug.Log("Invalid Firefly Requested");
                return;
            }

            fireflyInformation.fireflyInstance.GetComponent <FloatyFollowTarget>().UpdateTarget(target);
        }
Example #3
0
 private void Update()
 {
     for (int i = _fireflies.Count - 1; i >= 0; i--)
     {
         FireflyInformation fireflyInformation = _fireflies[i];
         if (fireflyInformation.destroyOnReachTarget && fireflyInformation.fireflyInstance.TargetReachedPosition())
         {
             DestroyFirefly(fireflyInformation.fireflyInstance.gameObject);
             _fireflies.RemoveAt(i);
         }
     }
 }
Example #4
0
        public void UpdateFireflyTargetToRandom(int fireflyIndex, bool destroyOnReach = false)
        {
            FireflyInformation fireflyInformation = _fireflies.FirstOrDefault(_ => _.fireflyIndex == fireflyIndex);

            if (fireflyInformation == null)
            {
                Debug.Log("Invalid Firefly Requested");
                return;
            }

            Transform randomTarget = GetRandomTransformPoint();

            fireflyInformation.destroyOnReachTarget = destroyOnReach;
            fireflyInformation.fireflyInstance.GetComponent <FloatyFollowTarget>().UpdateTarget(randomTarget);
        }