Example #1
0
    public void Attack(bool isMoving, bool attack)
    {
        //creates a projectile clone
        if (attack && (attackTime <= Time.time && !isCreated))
        {
            //creates the projectile
            projectile       = Instantiate(projectilePrefab, attackSource.position, attackSource.rotation);
            projectileScript = projectile.GetComponent <ProjectileManager>();

            //updates and fetches projectile's data
            projectileScript.SetPlayerMoving(isMoving);
            fireRate    = fireRates[projectileScript.GetPName()];
            explodeType = projectileScript.GetExplosionType();

            //adds the score and updates the attack time
            GameplayScript.current.AddScore(scores["fire"]);
            attackTime = fireRate + Time.time;

            //start waiting if it's a detonation projectile
            if (explodeType == explosionType.Detonate)
            {
                isCreated = true;
            }
        }

        //detonates the projectile using the button
        else if (attack && projectileScript != null)
        {
            StopCoroutine(coro);
            projectileScript.DetonateProjectile();
            isCreated = false;
        }
    }
 public ExplodeScript Setup(explosionType explosionType, float power, float radius)
 {
     ExplosionType = explosionType;
     Power         = power;
     Radius        = radius;
     return(this);
 }
        private GameObject getExplodeEffectObject(explosionType explosionType)
        {
            GameObject go = null;

            if (explosionType == explosionType.Large)
            {
                go = (GameObject)Instantiate(AssetManager.Instance.Explosion.largeExplosionEffect);
            }
            else if (explosionType == explosionType.Small)
            {
                go = (GameObject)Instantiate(AssetManager.Instance.Explosion.smallExplosionEffect);
            }
            else if (explosionType == explosionType.Firework)
            {
                go = (GameObject)Instantiate(AssetManager.Instance.Explosion.fireworkeExplosionEffect);
            }
            else if (explosionType == explosionType.Big)
            {
                go = (GameObject)Instantiate(AssetManager.Instance.Explosion.bigExplosionEffect);
            }
            else if (explosionType == explosionType.Smoke)
            {
                go = (GameObject)Instantiate(AssetManager.Instance.Explosion.smokeExplosionEffect);
            }
            return(go);
        }
Example #4
0
 public Effect(effectType _type, soundType _s_type, explosionType _e_type, int _x, int _y)
 {
     type   = _type;
     s_type = _s_type;
     e_type = _e_type;
     x      = _x;
     y      = _y;
 }
 public Effect(effectType _type, soundType _s_type, explosionType _e_type, int _x, int _y)
 {
     type = _type;
     s_type = _s_type;
     e_type = _e_type;
     x = _x;
     y = _y;
 }
    void Start()
    {
        //central throwing attributes
        s_Projectile.Init(rigid, playerMoving);
        explosionType explodeType = GetExplosionType();

        //activates delayed detonation for some projectiles
        if (explodeType == explosionType.Delay ||
            explodeType == explosionType.Detonate)
        {
            coro = StartCoroutine(WaitUntilDetonate());
        }

        //instantly explode this one because why not
        else if (explodeType == explosionType.Instant)
        {
            ExplodeProjectile();
        }
    }
        public void Explody_Network(explosionType explosionType, Vector3 position)
        {
            fireEffect = getExplodeEffectObject(explosionType);
            if (ExplosionType == explosionType.Big)
            {
                fireEffect.transform.FindChild("Debris").localRotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0f, 360f), Vector3.up);
            }
            fireEffect.transform.position = position;

            StartCoroutine(ParticleEffectEvent());

            IEnumerator ParticleEffectEvent()
            {
                yield return(new WaitForFixedUpdate());

                isExplodey = true;

                fireEffect.SetActive(true);
                fireEffect.AddComponent <TimedSelfDestruct>().Begin(30f);
                yield return(new WaitForSeconds(3f));

                fireEffect.SetActive(false);
            }
        }
Example #8
0
 public void RequestExplosion(explosionType e_type, int _x, int _y)
 {
     all_effects.Add(new Effect(effectType.EXPLOSION, soundType.SHOOT, explosionType.SMALL, _x, _y));
 }
Example #9
0
 public void LoadExplosion(ContentManager cont_man, string _path, explosionType e_type)
 {
     expls[(int)e_type] = new Sprite();
     expls[(int)e_type].Load(cont_man, _path, 16, 16, 200);
 }
 public void Explodey(explosionType explosiontype, Vector3 position, float power, float radius)
 {
     StartCoroutine(explodey(explosiontype, position, power, radius));
 }
        private IEnumerator explodey(explosionType explosiontype, Vector3 position, float power, float radius)
        {
            if (StatMaster.isClient)
            {
                yield break;
            }

            if (isExplodey)
            {
                yield break;
            }
            else
            {
                fireEffect = getExplodeEffectObject(explosiontype);
                if (ExplosionType == explosionType.Big)
                {
                    fireEffect.transform.FindChild("Debris").localRotation = Quaternion.AngleAxis(UnityEngine.Random.Range(0f, 360f), Vector3.up);
                }
                fireEffect.transform.position = position;

                if (!StatMaster.isClient)
                {
                    var message = ExplodyMessage.CreateMessage((int)explosiontype, position);
                    ModNetworking.SendToAll(message);
                }
            }

            yield return(new WaitForFixedUpdate());

            isExplodey = true;
            fireEffect.SetActive(true);
            OnExplode?.Invoke();

            //定义爆炸位置为炸弹位置
            Vector3 explosionPos = position;

            //这个方法用来返回球型半径之内(包括半径)的所有碰撞体collider[]
            Collider[] colliders = Physics.OverlapSphere(explosionPos, radius);

            //遍历返回的碰撞体,如果是刚体,则给刚体添加力
            foreach (Collider hit in colliders)
            {
                if (hit.attachedRigidbody != null)
                {
                    float force = UnityEngine.Random.Range(30000f, 50000f) * power * (Vector3.Distance(hit.transform.position, explosionPos) / (radius + 0.25f));
                    hit.attachedRigidbody.AddExplosionForce(force, explosionPos, radius);
                    hit.attachedRigidbody.AddTorque(force * Vector3.Cross((hit.transform.position - explosionPos), Vector3.up));

                    reduceBlockHealth(hit.attachedRigidbody.gameObject);
                }
            }

            OnExploded?.Invoke(colliders);
            yield return(new WaitForSeconds(3f));

            fireEffect.SetActive(false);
            OnExplodeFinal?.Invoke();
            //-------------------------------------------------------------
            void reduceBlockHealth(GameObject gameObject)
            {
                var bhb = gameObject.GetComponent <BlockHealthBar>();

                if (bhb != null)
                {
                    bhb.DamageBlock(1);
                }
            }

            //---------------------------------------------------------------
        }
 public void RequestExplosion(explosionType e_type, int _x, int _y)
 {
     all_effects.Add(new Effect(effectType.EXPLOSION, soundType.SHOOT, explosionType.SMALL, _x, _y));
 }
 public void LoadExplosion(ContentManager cont_man, string _path, explosionType e_type)
 {
     expls[(int)e_type] = new Sprite();
     expls[(int)e_type].Load(cont_man, _path, 16, 16, 200); // draw an explosion
 }