void Awake()
    {
        timedD = GetComponentInChildren <TimedDestruction> ();

        lifeTime   = timedD.delayTime;
        startScale = transform.localScale;
    }
Example #2
0
        public void TriggerConnection(Vector3 targetPos)
        {
            Vector3 center = m_chestBounds.center;

            GameObject m_connection = Object.Instantiate(m_connectionPrefab, center, Quaternion.identity);

            TimedDestruction timedDestruction = m_connection.AddComponent <TimedDestruction>();

            Vector3    vector   = targetPos - center;
            Quaternion rotation = Quaternion.LookRotation(vector.normalized);

            timedDestruction.Trigger(vector.magnitude);
            m_connection.transform.position   = center;
            m_connection.transform.rotation   = rotation;
            m_connection.transform.localScale = new Vector3(1f, 1f, vector.magnitude);
        }
Example #3
0
        /// <summary>
        ///     Spawn a prefab without any Components except visuals. Also prevents calling Awake methods of the prefab.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private static RenderObject SpawnSafe(RenderRequest request)
        {
            GameObject prefab = request.Target;

            // map prefab GameObjects to the instantiated GameObjects
            Dictionary <GameObject, GameObject> realToClone = new Dictionary <GameObject, GameObject>();
            GameObject spawn = SpawnOnlyTransformsClone(prefab, null, realToClone);

            foreach (var pair in realToClone)
            {
                CopyVisualComponents(pair.Key, pair.Value, realToClone);
            }

            spawn.transform.position = Vector3.zero;
            spawn.transform.rotation = request.Rotation;
            spawn.name = prefab.name;

            // calculate visual center
            Vector3 min = new Vector3(1000f, 1000f, 1000f);
            Vector3 max = new Vector3(-1000f, -1000f, -1000f);

            foreach (Renderer meshRenderer in spawn.GetComponentsInChildren <Renderer>())
            {
                min = Vector3.Min(min, meshRenderer.bounds.min);
                max = Vector3.Max(max, meshRenderer.bounds.max);
            }

            // center the prefab
            spawn.transform.position = SpawnPoint - (min + max) / 2f;
            Vector3 size = new Vector3(
                Mathf.Abs(min.x) + Mathf.Abs(max.x),
                Mathf.Abs(min.y) + Mathf.Abs(max.y),
                Mathf.Abs(min.z) + Mathf.Abs(max.z));

            // just in case it doesn't gets deleted properly later
            TimedDestruction timedDestruction = spawn.AddComponent <TimedDestruction>();

            timedDestruction.Trigger(1f);

            return(new RenderObject(spawn, size)
            {
                Request = request
            });
        }
Example #4
0
    // Update is called once per frame
    void Update()
    {
        if (senabled)
        {
            if (smokeInstance != null)
            {
                smokeInstance.transform.position = effectSpawn.position;                //transform.position+self.collider.bounds.extents.y*transform.up+transform.forward*self.collider.bounds.extents.z*0.5f;
                smokeInstance.transform.rotation = transform.rotation;
            }
            if (flameInstance != null)
            {
                flameInstance.transform.position = effectSpawn.position;                //transform.position+self.collider.bounds.extents.y*transform.up+transform.forward*self.collider.bounds.extents.z*0.5f;
                flameInstance.transform.rotation = transform.rotation;
                StartCoroutine(burnDamage());
            }
            if (hp > maxHp / 4 && hp <= maxHp / 2 && smokeInstance == null)
            {
                smokeInstance = Instantiate(smoke, transform.position, transform.rotation) as GameObject;
                smokeInstance.GetComponent <ParticleFX_Main>().scale = size;
                if (soundSource != null)
                {
                    soundSource.loop = true;
                    soundSource.clip = smokeSound;
                    soundSource.Play();
                }
            }
            else if (hp > 0 && hp <= maxHp / 4 && flameInstance == null)
            {
                if (smokeInstance != null)
                {
                    TimedDestruction SmokeTimer = smokeInstance.AddComponent <TimedDestruction>();
                    SmokeTimer.TimeToDestruct = 10f;
                    SetEmission(smokeInstance, false);
                    smokeInstance = null;
                }
                if (soundSource != null)
                {
                    soundSource.Stop();
                    soundSource.loop = true;
                    soundSource.clip = flameSound;
                    soundSource.Play();
                }

                flameInstance = Instantiate(flame, transform.position, transform.rotation) as GameObject;
                flameInstance.GetComponent <ParticleFX_Main>().scale = size;
            }
            else if (hp <= 0 && explosionInstance == null)
            {
                if (flameInstance != null)
                {
                    TimedDestruction FlameTimer = flameInstance.AddComponent <TimedDestruction>();
                    FlameTimer.TimeToDestruct = 5f;
                    SetEmission(flameInstance, false);
                    flameInstance = null;
                }
                explosionInstance = Instantiate(explosion, effectSpawn.position /*transform.position+transform.up*self.collider.bounds.extents.y*/, transform.rotation) as GameObject;
                explosionInstance.GetComponent <ParticleFX_Main>().scale = size;
                if (explosionSound != null)
                {
                    AudioSource explosionAudio = explosionInstance.AddComponent <AudioSource>();
                    explosionAudio.minDistance = 10f;
                    explosionAudio.spread      = 3f;
                    explosionAudio.PlayOneShot(explosionSound, 1F);
                }
                Destroy(gameObject);
            }
        }
    }