Пример #1
0
    private static IEnumerator Hunter(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        while (!script.homer)//wait for homingscript reference
        {
            yield return(new WaitForEndOfFrame());
        }
        HomingScript home = script.homer.GetComponent <HomingScript>();

        while (!home.homing && !script.has_collided)//Wait untuil it homes or collides
        {
            yield return(new WaitForEndOfFrame());
        }
        Collider[] bullet_colliders = Physics.OverlapSphere(script.gameObject.transform.position,
                                                            10,
                                                            LayerMask.GetMask("Default"),
                                                            QueryTriggerInteraction.Collide);
        foreach (Collider col in bullet_colliders)
        {
            /*Check if its a flurry bullet that isn't isn't homing*/
            BulletScript b = col.GetComponent <BulletScript>();
            if (b &&
                b.gameObject.layer == script.gameObject.layer &&
                b.gun_reference is Flurry &&
                !b.homer.GetComponent <HomingScript>().homing &&
                home.main_col)
            {
                /*Make bullet face target and fire towards them*/
                b.transform.LookAt(new Vector3(home.main_col.gameObject.transform.position.x, script.transform.position.y, home.main_col.gameObject.transform.position.z));
                b.GetComponent <Rigidbody>().velocity = b.transform.forward * b.GetComponent <Rigidbody>().velocity.magnitude;
            }
        }
        script.coroutines_running--;
    }
Пример #2
0
 public override void use()
 {
     if (activeTime > 0)
     {
         left       = Instantiate(template, p.transform.position, Quaternion.identity);
         right      = Instantiate(template, p.transform.position, Quaternion.identity);
         left.obj   = right.obj = p;
         activeTime = -1;
         p.itemCD   = p.itemCDTime;
     }
     else if (activeTime < 0)
     {
         Vector2 leftVel    = left.GetComponent <Rigidbody2D>().velocity;
         Vector2 rightVel   = right.GetComponent <Rigidbody2D>().velocity;
         double  leftAngle  = Math.Atan(leftVel.y / leftVel.x);
         double  rightAngle = Math.Atan(leftVel.y / leftVel.x);
         Debug.Log(leftAngle + "    " + rightAngle);
         double leftNewAngle  = Math.Atan(leftVel.y / leftVel.x) + Math.PI / 2;
         double rightNewAngle = Math.Atan(leftVel.y / leftVel.x) - Math.PI / 2;
         Debug.Log(leftNewAngle + "    " + rightNewAngle);
         left.GetComponent <Rigidbody2D>().velocity  = new Vector2((float)Math.Cos(leftNewAngle) * left.speed, (float)Math.Sin(leftNewAngle) * left.speed);
         right.GetComponent <Rigidbody2D>().velocity = new Vector2((float)Math.Cos(rightNewAngle) * left.speed, (float)Math.Sin(rightNewAngle) * left.speed);
         activeTime = 1;
     }
 }
Пример #3
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag.Equals("Bullet"))
        {
            BulletScript bulletScript = other.gameObject.GetComponent <BulletScript>();

            switch (bulletScript.ReturnBulletType())
            {
            case BulletScript.BulletType.Minigun:
                HealthPoint -= bulletScript.BulletDamage;
                break;

            case BulletScript.BulletType.Normal:
                HealthPoint -= bulletScript.BulletDamage;
                break;
            }

            Destroy(bulletScript.gameObject);
            bulletScript.GetComponent <Collider>().enabled = false;

            if (HealthPoint <= 0)
            {
                if (Achievement.minionKills < 10)
                {
                    Achievement.minionKills++;
                }

                Dead();
            }
        }
    }
Пример #4
0
    private static IEnumerator Engulf(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        while (!script.Target)
        {
            yield return(new WaitForEndOfFrame());
        }
        Rigidbody rb  = script.GetComponent <Rigidbody>();
        Rigidbody trb = script.Target.GetComponent <Rigidbody>();

        if (trb)
        {
            rb.freezeRotation         = true;
            script.transform.position = new Vector3(script.Target.transform.position.x,
                                                    script.transform.position.y,
                                                    script.Target.transform.position.z);
            script.coroutines_running--;
            while (script)
            {
                rb.velocity = new Vector3(trb.velocity.x,
                                          0,
                                          trb.velocity.z);
                yield return(new WaitForFixedUpdate());
            }
        }
        else
        {
            rb.velocity = Vector3.zero;
        }
    }
Пример #5
0
    private static IEnumerator Infect(Gun gun, BulletScript script)
    {
        List <uint> IDs = new List <uint>();

        IDs.Add(script.netId.Value);
        while (script)
        {
            float      radius           = script.GetComponent <BoxCollider>().size.z;
            Collider[] bullet_colliders = Physics.OverlapSphere(script.gameObject.transform.position,
                                                                radius,
                                                                LayerMask.GetMask(
                                                                    LayerMask.LayerToName(script.gameObject.layer)),
                                                                QueryTriggerInteraction.Collide);
            foreach (Collider col in bullet_colliders)
            {
                BulletScript b = col.gameObject.GetComponent <BulletScript>();
                if (b && !IDs.Contains(b.netId.Value))
                {
                    IDs.Add(b.netId.Value);
                    b.chill_strength     += .05;
                    b.burn_strength      += .05;
                    b.mezmerize_strength += .05;
                    b.sunder_strength    += .05;
                }
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Пример #6
0
    private static IEnumerator Randomizer(Gun gun, BulletScript script)
    {
        float num = UnityEngine.Random.Range(.5f, 2.5f);

        while (!script.homer)
        {
            yield return(new WaitForEndOfFrame());
        }
        HomingScript h = script.homer.GetComponent <HomingScript>();

        if (!script.Target && !h.main_col)
        {
            NetworkMethods.Instance.RpcSetEnabled(script.gameObject, "Renderer", false);
            NetworkMethods.Instance.RpcSetLayer(script.gameObject, 16);
            Rigidbody rb    = script.GetComponent <Rigidbody>();
            Vector3   speed = rb.velocity;
            rb.velocity = Vector3.zero;
            float start_time = Time.time;
            while (start_time + num > Time.time && !h.main_col && !script.Target)
            {
                yield return(new WaitForEndOfFrame());
            }
            NetworkMethods.Instance.RpcSetEnabled(script.gameObject, "Renderer", true);
            NetworkMethods.Instance.RpcSetLayer(script.gameObject, gun.layer);
            rb.velocity = speed.magnitude * script.transform.forward;
        }
    }
Пример #7
0
    private static IEnumerator Comet(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        Rigidbody rb = script.GetComponent <Rigidbody>();

        yield return(new WaitForFixedUpdate());

        rb.velocity *= 3;
        script.coroutines_running--;
        yield return(null);
    }
Пример #8
0
    public void Fire()
    {
        BulletScript b = Instantiate(bullet, muzzle.position, muzzle.rotation) as BulletScript;

        b.turretCollider = GetComponent <Collider> ();
        b.GetComponent <Rigidbody> ().velocity = Velocity * muzzle.forward;
        if (MuzzleFlash)
        {
            Instantiate(MuzzleFlash, muzzle.position, muzzle.rotation);
        }
    }
Пример #9
0
    private static IEnumerator Debris(Gun gun, BulletScript script)
    {
        script.lasting_time *= 2;
        yield return(new WaitForSeconds(1f));

        script.homer.GetComponent <HomingScript>().home_speed /= 2;
        script.transform.position = new Vector3(
            script.transform.position.x,
            script.transform.position.y + 1f,
            script.transform.position.z);
        NetworkMethods.Instance.RpcSetScale(script.gameObject, Vector3.one * 2);
        script.GetComponent <Rigidbody>().velocity /= 2;
    }
Пример #10
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag.Equals("Bullet"))
        {
            if (bossState != BossState.Shield)
            {
                BulletScript bulletScript = other.gameObject.GetComponent <BulletScript>();
                HealthPoint -= bulletScript.BulletDamage;

                bulletScript.GetComponent <Collider>().enabled = false;
                if (HealthPoint <= 0)
                {
                    Dead();
                    if (Achievement.bossKills < 1)
                    {
                        Achievement.bossKills = 1;
                    }
                }
            }
            Destroy(other.gameObject);
        }
    }
Пример #11
0
    private static IEnumerator Seeker(Gun gun, BulletScript script)
    {
        while (!script.Target)
        {
            yield return(new WaitForEndOfFrame());
        }
        List <HealthDefence> hp       = new List <HealthDefence>();
        Rigidbody            rb       = script.GetComponent <Rigidbody>();
        SphereCollider       home_col = script.homer.GetComponent <SphereCollider>();
        float speed_boost             = rb.velocity.magnitude * .2f;
        float home_boost = home_col.radius * .2f;

        while (script)
        {
            if (!hp.Contains(script.Target))
            {
                hp.Add(script.Target);
                rb.velocity      = script.transform.forward * (rb.velocity.magnitude + speed_boost);
                home_col.radius += home_boost;
            }
            yield return(new WaitForEndOfFrame());
        }
    }
Пример #12
0
    private static IEnumerator Scout(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        while (!script.Target)
        {
            yield return(new WaitForEndOfFrame());
        }
        script.lasting_time += 3.2f;
        script.GetComponent <Rigidbody>().velocity = Vector3.zero;
        NetworkMethods.Instance.RpcSetEnabled(script.gameObject, "Collider", false);
        NetworkMethods.Instance.RpcSetEnabled(script.gameObject, "Renderer", false);
        script.coroutines_running--;
        script.can_bounce = true;
        if (gun.client_user && gun.client_user.speed < 27)
        {
            gun.client_user.speed        += 3;
            gun.client_user.shield_speed += 3;
            yield return(new WaitForSeconds(3));

            gun.client_user.speed        -= 3;
            gun.client_user.shield_speed -= 3;
        }
        else
        {
            AIController AI = gun.GetComponentInParent <AIController>();
            if (AI && AI.speed < 32)
            {
                AI.speed        += 4;
                AI.shield_speed += 4;
                yield return(new WaitForSeconds(3));

                AI.speed        -= 4;
                AI.shield_speed -= 4;
            }
        }
        script.can_bounce = false;
    }
Пример #13
0
    private static IEnumerator Thirst(Gun gun, BulletScript script)
    {
        Vector3   start_pos = script.transform.position;
        Rigidbody rb        = script.GetComponent <Rigidbody>();

        while (!script.homer)
        {
            yield return(new WaitForEndOfFrame());
        }
        HomingScript   hm              = script.homer.GetComponent <HomingScript>();
        SphereCollider col             = hm.GetComponent <SphereCollider>();
        float          original_radius = col.radius;

        while (script)
        {
            if (!hm.homing)
            {
                col.radius          += original_radius * .1f;
                hm.home_speed       += .1f;
                script.lasting_time += .001f;
            }
            yield return(new WaitForFixedUpdate());
        }
    }
Пример #14
0
    private static IEnumerator Camouflage(Gun gun, BulletScript script)
    {
        script.coroutines_running++;
        Renderer rend   = script.GetComponent <Renderer>();
        Color    origin = rend.material.color;

        if (rand.NextDouble() < .3)
        {
            if (gun.layer == 13)
            {
                /*Undetectable ally layer added to make it seems like enemies
                 * can't respond(block or dodge) it due to it not colliding with
                 * defensive detection.*/
                script.gameObject.layer = 16;
                rend.material.color     = new Color(origin.r, origin.g, origin.b, .3f);
            }
            else
            {
                rend.material.color = new Color(origin.r, origin.g, origin.b, .2f);
            }
        }
        script.coroutines_running--;
        yield return(null);
    }
Пример #15
0
    private static IEnumerator Accelerate(Gun gun, BulletScript script)
    {
        Vector3   start_pos = script.transform.position;
        Rigidbody rb        = script.GetComponent <Rigidbody>();

        while (!script.homer)
        {
            yield return(new WaitForEndOfFrame());
        }
        HomingScript hm = script.homer.GetComponent <HomingScript>();

        while (script)
        {
            if (!hm.homing)
            {
                rb.velocity = rb.velocity.normalized
                              * (rb.velocity.magnitude
                                 + Math.Abs(
                                     Vector3.Distance(start_pos, script.transform.position))
                                 / 10);
            }
            yield return(new WaitForFixedUpdate());
        }
    }
Пример #16
0
    private void Update()
    {
        //code to use with space key

        /* if(Input.GetKeyDown(KeyCode.Space))
         * {
         *   InvokeRepeating(SHOOT_METHOD, 0f, firingRate);
         * }
         * if(Input.GetKeyUp(KeyCode.Space))
         * {
         *   CancelInvoke(SHOOT_METHOD);
         * }*/
        if (Time.time > nextfire)
        {
            nextfire = Time.time + firingRate;

            BulletScript bullet = Instantiate(bulletPrefab, bulletParent.transform);
            bullet.transform.position = transform.position;
            Rigidbody2D rb = bullet.GetComponent <Rigidbody2D>();
            rb.velocity = Vector3.up * bulletSpeed;

            audioBul.Play();
        }
    }
Пример #17
0
    void OnCollisionEnter(Collision c)
    {
        BulletScript bScript = c.gameObject.GetComponent <BulletScript> ();

        if (bScript == null)
        {
            return;
        }
        //Debug.Log ("The frequency is " + bScript.freq);



        if (lightType == bScript.lightType)
        {
            if (freqaffectphysics)
            {
                Vector3 imp = new Vector3(0f, 0f, 0f);

                imp = bScript.GetComponent <Rigidbody>().mass *(c.rigidbody.velocity - bScript.GetComponent <Rigidbody>().velocity);

                c.rigidbody.AddForce(imp * 10.0f, ForceMode.Impulse);

                //				b.GetComponent<Rigidbody> ().AddForce
                //					(m_Camera.transform.forward * newVelocity/10, ForceMode.Impulse);
            }


            if (destroyonhit)
            {
                Destroy(this.gameObject);
            }
            if (flipGravity)
            {
                if (isGravityFlipped == false)
                {
                    try {
                        this.GetComponent <Rigidbody> ().useGravity = false;
                        isGravityFlipped = true;
                    } catch {
                        Debug.Log("No rigid body found.");
                    }
                }
                else
                {
                    try {
                        this.GetComponent <Rigidbody> ().useGravity = true;
                        isGravityFlipped = false;
                    } catch {
                        Debug.Log("No rigid body found.");
                    }
                }
            }
            if (changeScale)
            {
                scaling = true;
            }
            if (changePosition)
            {
                moving = true;
            }
        }
    }
Пример #18
0
    void OnTriggerStay2D(Collider2D other)
    {
        MovementScript movementScript = GetComponent <MovementScript> ();
        bool           hit            = false;
        int            otherId        = 1;
        Color          hitCol         = new Color(1f, .5f, 0f);

        if (!invincibilty)
        {
            if (other.tag == "Bullet")
            {
                BulletScript bulletScript = other.GetComponent <BulletScript> ();
                if (bulletScript.id == id)
                {
                    return;
                }
                if (movementScript.team != 0 && bulletScript.team == movementScript.team)
                {
                    return;
                }
                health -= bulletScript.damage;
                LaserBulletScript lbs = bulletScript.GetComponent <LaserBulletScript> ();
                if (lbs == null)
                {
                    Destroy(other.gameObject);
                }
                if (!movementScript.isJuggernaut)
                {
                    StartCoroutine(InvincibilityRoutine(30f));
                }
                hit     = true;
                otherId = bulletScript.id;
                //GetComponent<PlayerEnemyHandler> ().CreateNumber (transform.position, bulletScript.damage.ToString(), hitCol, .1f, 120f, 3f);
                LucyFreezeBulletScript lucyFreeze = other.GetComponent <LucyFreezeBulletScript> ();
                if (lucyFreeze != null)
                {
                    movementScript.move_mult = Mathf.Max(lucyFreeze.slowMax, movementScript.move_mult - lucyFreeze.slowAmount);
                }
            }

            if (other.tag == "Enemy")
            {
                EnemyScript enemyScript = other.GetComponent <EnemyScript> ();
                if (enemyScript.id == id)
                {
                    return;
                }
                if (movementScript.team != 0 && enemyScript.team == movementScript.team)
                {
                    return;
                }
                float damage;
                if (enemyScript.type == 0)
                {
                    health -= 25f;
                    damage  = 25f;
                }
                else
                {
                    health -= 5f;
                    damage  = 5f;
                }
                if (gameObject.activeSelf)
                {
                    StartCoroutine(InvincibilityRoutine(30f));
                }
                hit     = true;
                otherId = enemyScript.id;
                //GetComponent<PlayerEnemyHandler> ().CreateNumber (transform.position, damage.ToString(), hitCol, .1f, 120f, 3f);
            }

            if (hit)
            {
                GetComponentInChildren <AudioManager> ().Play(1);
                GetComponentInChildren <ParticleController> ().Play(3);
                GetComponent <Rigidbody2D>().MovePosition(transform.position + (Vector3.ClampMagnitude(-transform.position + other.transform.position * 10f, .25f)));
            }

            if (health <= 0f)
            {
                GameManager gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager> ();
                if (GameManager.gameMode == GAMEMODE.PVP)
                {
                    ChildQueueController.player_profiles [id - 1].deaths++;
                    ChildQueueController.player_profiles [otherId - 1].kills++;
                }

                GameObject[] playerTemp = GameObject.FindGameObjectsWithTag("Player");                  // Crea Number

                GameObject killer = null;
                for (int i = 0; i < playerTemp.Length; i++)
                {
                    if (playerTemp [i] == null)
                    {
                        continue;
                    }
                    if (playerTemp [i].GetComponent <MovementScript> ().player_num == otherId)
                    {
                        killer = playerTemp [i];
                        break;
                    }
                }

                if (killer != null)
                {
                    //killer.GetComponent<PlayerEnemyHandler>().CreateNumber(killer.transform.position,"+10% Damage", Color.red, .05f, 60f, 1f);
                }


                //Buff
                WeaponManager[] temp = FindObjectsOfType <WeaponManager> ();

                for (int i = 0; i < temp.Length; i++)
                {
                    if (temp[i].player_num == otherId)
                    {
                        temp [i].weapons [0].personalDamageMult += .1f;
                    }
                }
                if (GameManager.gameMode == GAMEMODE.PVP)
                {
                    gameManager.playerKills [otherId - 1]++;
                }
                else if (GameManager.gameMode == GAMEMODE.PVE)
                {
                    gameManager.enemyMult  = Mathf.Floor(gameManager.enemyMult / .5f);
                    gameManager.enemyMult *= .5f;
                    //gameManager.enemyMult = 1f;
                }
                lives--;

                if (GameManager.gameMode == GAMEMODE.JUGGERNAUT)
                {
                    lives = Mathf.Max(lives, 1);
                    gameManager.juggernautPoints [otherId - 1]++;
                }

                GetComponent <PlayerEnemyHandler> ().Disband();
                Instantiate(diePrefab, transform.position, Quaternion.identity);
                death.Play();

                //Juggernaut
                if (GameManager.gameMode == GAMEMODE.JUGGERNAUT)
                {
                    if (GetComponent <MovementScript> ().isJuggernaut)
                    {
                        killer.GetComponent <MovementScript> ().BecomeJuggernaut();
                        GetComponent <MovementScript> ().UnbecomeJuggernaut();
                    }
                }

                if (lives > 0)
                {
                    gameManager.StartCoroutine(gameManager.RespawnPlayer(gameObject));
                }
                else
                {
                    ChildQueueController.player_profiles [id - 1].losses++;
                }
                stunStack     = 0;
                stunText.text = "";
                GetComponentInChildren <DanielShooterScript> ().Reset();
                GetComponent <WeaponManager> ().input_active = true;
                gameObject.SetActive(false);
            }
        }
    }
Пример #19
0
    public void Fire(bool isEnemy, Transform firedShip)
    {
        // Check if it can fire
        if (canFire)
        {
            switch (gunType)
            {
            case GameConstants.GunTypes.MachineGun:
                BulletScript newBullet = gameManager.GetBullet(gunType, transform).GetComponent <BulletScript>();
                newBullet.transform.position = transform.position + transform.forward;
                newBullet.transform.rotation = transform.rotation;
                newBullet.isEnemyShot        = isEnemy;
                newBullet.GetComponent <Rigidbody>().velocity = firedShip.GetComponent <Rigidbody>().velocity;
                newBullet.gameObject.SetActive(true);
                newBullet.FireBullet();
                musicPlayer.clip = bulletSound;
                if (!musicPlayer.isPlaying)
                {
                    musicPlayer.Play();
                }
                // Set transform and set initial velocity of rigidbody component
                break;

            case GameConstants.GunTypes.ShotGun:
                // Do it for 5 shots
                for (int i = 0; i < 6; i++)
                {
                    ShotgunBulletScript newShoutgunBullet = gameManager.GetBullet(gunType, transform).GetComponent <ShotgunBulletScript>();
                    newShoutgunBullet.transform.position    = transform.position + transform.forward;
                    newShoutgunBullet.transform.eulerAngles = new Vector3(transform.eulerAngles.x, transform.eulerAngles.y + Random.Range(-10f, 10f), transform.eulerAngles.z);
                    newShoutgunBullet.isEnemyShot           = isEnemy;
                    // Set bullet velocity to ship velocity
                    newShoutgunBullet.GetComponent <Rigidbody>().velocity = firedShip.GetComponent <Rigidbody>().velocity;
                    newShoutgunBullet.gameObject.SetActive(true);
                    newShoutgunBullet.FireShotgun();
                }
                musicPlayer.clip = shotgunSound;
                if (!musicPlayer.isPlaying)
                {
                    musicPlayer.Play();
                }
                // Get 5-10 ShotGun Bullets from GameManager.ShotGunBulletPool
                // Give random spread to rotation/initial position
                // Set Initial Velocity of rigidbody
                break;

            case GameConstants.GunTypes.LaserGun:
                LaserBulletScript newLaserBullet = gameManager.GetBullet(gunType, transform).GetComponent <LaserBulletScript>();
                newLaserBullet.transform.position = transform.position + transform.forward;
                newLaserBullet.transform.SetParent(transform);

                float randomY = transform.eulerAngles.y + (isEnemy ? Random.Range(-5f, 5f) : 0f);
                newLaserBullet.transform.eulerAngles = new Vector3(transform.eulerAngles.x, randomY, transform.eulerAngles.z);
                newLaserBullet.isEnemyShot           = isEnemy;

                newLaserBullet.gameObject.SetActive(true);
                newLaserBullet.FireLaser();
                musicPlayer.clip = laserSound;
                if (!musicPlayer.isPlaying)
                {
                    musicPlayer.Play();
                }
                break;
            }
            // Cannot fire and start Coroutine to be able to fire next
            canFire = false;
            StartCoroutine(ResetCanFire());
        }
    }