Inheritance: MonoBehaviour
Exemple #1
0
 private void Update()
 {
     if (mType != FireworkController.LaunchType.None)
     {
         FireworkController.Launch(mType);
         mType = FireworkController.LaunchType.None;
     }
 }
 void OnCollisionEnter2D(Collision2D collision)
 {
     if (isTouchingFlagpole && collision.gameObject.tag == "Castle")
     {
         collision.gameObject.GetComponent <TilemapCollider2D>().enabled = false;
     }
     if (isTouchingFlagpole && collision.gameObject.tag == "FinishingBrick")
     {
         FinishingCastleFlagMover finishingFlagMover = FindObjectOfType <FinishingCastleFlagMover>();
         finishingFlagMover.Move();
         playerSpriteRenderer.enabled = false;
         int fireworksNumber = (int)FindObjectOfType <ScoreManager>().GetCurrentTime() % 10;
         FireworkController fireworkController = new FireworkController();
         StartCoroutine(fireworkController.SpawnFireworks(fireworksNumber, firework));
     }
 }
Exemple #3
0
            private void Start()
            {
                // Declare counter, color, and scale variables here so
                // we can re-use them
                int     i     = 0;
                int     count = 0;
                Color   c     = FireworkController.GetColor();
                Vector3 scale = Vector3.one;

                // Reference the explosion audio source
                mAudioSource = GetComponent <AudioSource>();

                // Pick firework type
                mType = (ExplosionType)((int)Random.Range(1.0f, (float)Firework.ExplosionType.Count));

                // Calculate rocket direction
                mNormal.x = Random.Range(-0.15f, 0.15f);
                mNormal.y = Random.Range(0.85f, 1.0f);
                mNormal.z = Random.Range(-0.15f, 0.15f);
                mNormal.Normalize();

                // Find and set up the rocket
                if (transform.childCount > 0)
                {
                    Transform child = transform.GetChild(0);
                    if (child != null)
                    {
                        mRocket = child.gameObject;
                        if (mRocket != null)
                        {
                            mRocket.transform.localPosition = Vector3.zero;

                            // Orient the rocket to its travel direction
                            mRocket.transform.localRotation = Quaternion.Euler(mNormal * Mathf.Rad2Deg);

                            // Randomly play screamer audio
                            AudioSource[] a = mRocket.GetComponentsInChildren <AudioSource>();
                            if (a.Length > 1)
                            {
                                for (i = 0; i < a.Length; i++)
                                {
                                    if (a[i] != null && a[i].clip != null && (i == 0 || Random.value > 0.8f))
                                    {
                                        a[i].Play();
                                    }
                                }
                            }
                        }
                    }
                }

                // Choose a final destination for the rocket
                mExplodePosition = mNormal * Random.Range(20.0f, 25.0f);

                // Populate a list of explosions to play after the rocket
                // reaches its destination
                if (mExplosions != null)
                {
                    switch (mType)
                    {
                    case ExplosionType.Radial:

                        // Set up radial explosions
                        count = Random.Range(1, 4);
                        for (i = 0; i < count; i++)
                        {
                            GameObject go = CreateExplosion(FireworkController.GetColor());
                            if (go != null)
                            {
                                go.transform.localPosition = mExplodePosition;
                                go.transform.localRotation = Quaternion.Euler(Vector3.one * Random.value * 360.0f);
                                go.transform.localScale    = go.transform.localScale * FireworkController.RandomScale();

                                mExplosions.Add(go);
                            }
                        }
                        break;

                    case ExplosionType.Spherical:

                        // Use the single radial explosion to form a sphere
                        count = Random.Range(3, 7);
                        scale = Vector3.one * FireworkController.RandomScale();
                        for (i = 0; i < count; i++)
                        {
                            GameObject go = CreateExplosion(c);
                            if (go != null)
                            {
                                go.transform.localPosition = mExplodePosition;
                                go.transform.localRotation = Quaternion.Euler(Vector3.one * ((float)i / (float)count) * 360.0f);
                                Vector3 s = go.transform.localScale;
                                s.x *= scale.x;
                                s.y *= scale.y;
                                s.z *= scale.z;
                                go.transform.localScale = s;

                                mExplosions.Add(go);
                            }
                        }
                        break;

                    case ExplosionType.Large:
                    {                             // The large explosion animation
                        GameObject go = CreateExplosion(c);
                        if (go != null)
                        {
                            go.transform.localPosition = mExplodePosition;
                            Vector3 s = go.transform.localScale;
                            scale = Vector3.one * FireworkController.RandomScale();
                            s.x  *= scale.x;
                            s.y  *= scale.y;
                            s.z  *= scale.z;
                            go.transform.localScale = s;

                            mExplosions.Add(go);
                        }
                    }

                    break;
                    }
                }

                // Mark the time the rocket started
                mRocketTime = Time.realtimeSinceStartup;
            }
Exemple #4
0
            private void Update()
            {
                float e = Time.realtimeSinceStartup;

                if (mRocket != null)
                {
                    // Use time and easing to plot the rocket's position
                    float t = (e - mRocketTime) / FireworkController.GetRocketDuration();
                    t -= 1.0f;
                    t  = Mathf.Pow(t, FireworkController.GetRocketEasing()) + 1.0f;
                    mRocket.transform.localPosition = mExplodePosition * t;

                    // Rocket animation is complete
                    if (t >= 1.0f)
                    {
                        // Play the explosion audio and destroy the rocket
                        Destroy(mRocket);
                        mRocket = null;
                        if (mAudioSource != null)
                        {
                            mAudioSource.clip = FireworkController.GetExplosion();
                            if (mAudioSource.clip != null)
                            {
                                mAudioSource.Play();
                            }
                        }

                        // Mark the explode time so we can clean up
                        // the scene in a bit
                        mExplodeTime = e;
                    }
                }

                // 'Sploded
                if (mExplodeTime > 0.0f)
                {
                    // Play the explosions
                    if (mExplosions != null)
                    {
                        foreach (GameObject go in mExplosions)
                        {
                            if (go != null && !go.activeInHierarchy)
                            {
                                Animator a = go.GetComponent <Animator>();
                                if (a != null)
                                {
                                    a.enabled = true;
                                }
                                go.SetActive(true);
                            }
                        }
                    }

                    // Mark this as complete after the appropriate delay
                    // to tell ARScene to destroy this game object
                    if (e - mExplodeTime > (mType == ExplosionType.Large ? 3.0f : 1.0f))
                    {
                        mComplete = true;
                    }
                }
            }
Exemple #5
0
            private void Update()
            {
                // Use keyboard keys to test launch types
#if UNITY_EDITOR
                if (Input.GetKeyUp(KeyCode.Alpha1))
                {
                    FireworkController.Launch(FireworkController.LaunchType.Single);
                }
                else if (Input.GetKeyUp(KeyCode.Alpha2))
                {
                    FireworkController.Launch(FireworkController.LaunchType.Dud);
                }
                else if (Input.GetKeyUp(KeyCode.Alpha3))
                {
                    FireworkController.Launch(FireworkController.LaunchType.Finale);
                }
                else if (Input.GetKeyUp(KeyCode.Alpha4))
                {
                    FireworkController.Launch(FireworkController.LaunchType.Fuse);
                }
#endif

                // Time to launch!
                float e = Time.realtimeSinceStartup;
                if (mLaunchTime > 0.0f && e - mLaunchTime > launchDelay)
                {
                    switch (mType)
                    {
                    case LaunchType.Dud:

                        // Fire the dud
                        if (dudPrefab != null)
                        {
                            ARScene.Append(dudPrefab);
                        }

                        break;

                    case LaunchType.Finale:

                        // Record the original delay values
                        mFinaleMaxDelay = finaleMaxDelay;
                        mFinaleMinDelay = finaleMinDelay;

                        // Choose a random number of fireworks and start the finale
                        mFinaleCount     = finaleMinCount + (int)(Random.value * Mathf.Abs((float)finaleMaxCount - (float)finaleMinCount));
                        mFinaleStartTime = Time.realtimeSinceStartup;

                        break;

                    case LaunchType.Fuse:

                        // Start the fuse animation
                        ARScene.Append(fusePrefab);
                        break;

                    case LaunchType.Single:

                        // Shoot off a firework
                        ARScene.Append(fireworkPrefab);

                        break;
                    }

                    // Ready for next launch
                    mLaunchTime = 0.0f;
                    mType       = LaunchType.None;
                }

                // Grand finale timing logic
                if (mFinaleStartTime > 0.0f && e - mFinaleStartTime > mFinaleDelay)
                {
                    Launch(LaunchType.Single);
                    mFinaleDelay     = finaleMinDelay + Random.value * (Mathf.Abs(finaleMaxDelay - finaleMinDelay));
                    finaleMaxDelay  *= finaleDelayDecay;
                    finaleMinDelay  *= finaleDelayDecay;
                    mFinaleStartTime = e;
                    --mFinaleCount;
                }

                // Restore delay values when the finale is complete
                if (mFinaleCount <= 0)
                {
                    finaleMaxDelay   = mFinaleMaxDelay;
                    finaleMinDelay   = mFinaleMinDelay;
                    mFinaleStartTime = 0.0f;
                }
            }
Exemple #6
0
 private void Awake()
 {
     sInstance = this;
 }