Exemplo n.º 1
0
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Obstacle")
     {
         ExplodingAsteroid temp  = collider.GetComponent <ExplodingAsteroid>();
         Asteroid          temp2 = collider.GetComponent <Asteroid>();
         Obstacle          temp3 = collider.GetComponent <Obstacle>();
         if (temp != null)
         {
             temp.Damage(1000);
         }
         else if (temp2 != null)
         {
             temp2.Damage(1000, MathHelper.degreeBetween2Points(collider.transform.position, transform.position), false);
         }
         else if (temp3 != null)
         {
             temp3.Damage(1000);
         }
         else
         {
             Debug.Log("Something collided with something it should not " + collider.name);
         }
     }
 }
Exemplo n.º 2
0
 IEnumerator PeriodicShock()
 {
     while (true)
     {
         List <GameObject> tempList = new List <GameObject>(asteroidsInRange);
         if (GameManager.Instance.isSoundOn && tempList.Count != 0)
         {
             fireSound.Play();
         }
         foreach (GameObject asteroid in tempList)
         {
             if (asteroid != null)
             {
                 GameObject effect = (GameObject)Instantiate(lightningEffect, transform.parent);
                 effect.transform.Find("Destination").transform.position = asteroid.transform.position;
                 //effect.transform.FindChild("Destination").transform.parent = asteroid.transform;
                 effect.transform.Find("Source").transform.position = transform.position;
                 ExplodingAsteroid temp  = asteroid.GetComponent <ExplodingAsteroid>();
                 Asteroid          temp2 = asteroid.GetComponent <Asteroid>();
                 Obstacle          temp3 = asteroid.GetComponent <Obstacle>();
                 if (temp != null)
                 {
                     temp.Damage(damage);
                 }
                 else if (temp2 != null)
                 {
                     temp2.Damage(damage, MathHelper.degreeBetween2Points(asteroid.transform.position, transform.position), false);
                 }
                 else if (temp3 != null)
                 {
                     temp3.Damage(damage);
                 }
                 else
                 {
                     Debug.Log("Something collided with something it should not " + GetComponent <Collider>().name);
                 }
                 //effect.GetComponent<Lightn>
             }
             else
             {
                 asteroidsInRange.Remove(asteroid);
             }
         }
         yield return(new WaitForSeconds(0.75f));
     }
 }
Exemplo n.º 3
0
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Obstacle")
     {
         ExplodingAsteroid temp  = collision.GetComponent <ExplodingAsteroid>();
         Asteroid          temp2 = collision.GetComponent <Asteroid>();
         Obstacle          temp3 = collision.GetComponent <Obstacle>();
         if (temp != null)
         {
             temp.Damage(damage);
         }
         else if (temp2 != null)
         {
             temp2.Damage(damage, MathHelper.degreeBetween2Points(collision.transform.position, transform.position), true);
         }
         else if (temp3 != null)
         {
             temp3.Damage(damage);
         }
         else
         {
             Debug.Log("Something collided with something it should not " + collision.name);
         }
     }
     else if (collision.tag == "Player")
     {
         PlayerController player = collision.GetComponent <PlayerController>();
         if (player != null)
         {
             player.Destroy();
         }
         else
         {
             Debug.Log("Something collided with something it should not");
         }
     }
 }
Exemplo n.º 4
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        startTime = Time.time;
        float      hp       = collider.GetComponent <Obstacle>().hp;
        GameObject asteroid = null;

        if (damage > hp)
        {
            float distance = float.MaxValue;
            for (int i = 0; i < GeneratorManager.Instance.asteroids.Count; i++)
            {
                if (GeneratorManager.Instance.asteroids[i] != collider.gameObject)
                {
                    float tempDistance = MathHelper.distanceBetween2Points(transform.position, GeneratorManager.Instance.asteroids[i].transform.position);
                    if (distance > tempDistance)
                    {
                        asteroid = GeneratorManager.Instance.asteroids[i];
                        distance = tempDistance;
                    }
                }
            }
            if (asteroid != null)
            {
                float degree = MathHelper.degreeBetween2Points(transform.position, asteroid.transform.position);
                rb.velocity = new Vector2(speed * (float)Mathf.Cos(degree * Mathf.PI / 180), speed * (float)Mathf.Sin(degree * Mathf.PI / 180));
            }
        }
        if (collider.tag == "Obstacle")
        {
            ExplodingAsteroid temp  = collider.GetComponent <ExplodingAsteroid>();
            Asteroid          temp2 = collider.GetComponent <Asteroid>();
            Obstacle          temp3 = collider.GetComponent <Obstacle>();
            if (temp != null)
            {
                temp.Damage(damage);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else if (temp2 != null)
            {
                temp2.Damage(damage, MathHelper.degreeBetween2Points(collider.transform.position, transform.position), false);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else if (temp3 != null)
            {
                temp3.Damage(damage);
                temp3.createDebris(transform.position, MathHelper.degreeBetween2Points(collider.transform.position, transform.position));
            }
            else
            {
                Debug.Log("Something collided with something it should not " + collider.name);
            }
        }
        transform.localScale *= (damage - hp) / damage;
        if (transform.localScale.x < 0.4f)
        {
            transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
        }
        damage -= hp;
        if (damage <= 0)
        {
            Destroy();
        }
    }
Exemplo n.º 5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        int layerMask = LayerMask.GetMask("Obstacle");

        if (currentLaserTimer < laserDuration)
        {
            lr.enabled = true;
            laserEffectEnd.gameObject.SetActive(true);
            RaycastHit2D hit = Physics2D.Raycast(transform.position, new Vector2(Mathf.Cos(player.transform.rotation.eulerAngles.z * Mathf.Deg2Rad), Mathf.Sin(player.transform.rotation.eulerAngles.z * Mathf.Deg2Rad)), 25, layerMask);
            lr.SetPosition(0, laserEffectStart.position);
            currentLaserTimer += Time.deltaTime;
            if (hit.collider != null)
            {
                lr.SetPosition(1, hit.point);
                laserEffectEnd.position = hit.point;
                ExplodingAsteroid temp  = hit.collider.GetComponent <ExplodingAsteroid>();
                Asteroid          temp2 = hit.collider.GetComponent <Asteroid>();
                Obstacle          temp3 = hit.collider.GetComponent <Obstacle>();
                if (temp != null)
                {
                    temp.Damage(damage * Time.fixedDeltaTime);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else if (temp2 != null)
                {
                    temp2.Damage(damage * Time.fixedDeltaTime, MathHelper.degreeBetween2Points(hit.transform.position, hit.point), false);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else if (temp3 != null)
                {
                    temp3.Damage(damage * Time.fixedDeltaTime);
                    if (lastDebriGenerateTime + 0.5f < Time.time)
                    {
                        temp3.createDebris(hit.point, MathHelper.degreeBetween2Points(hit.transform.position, hit.point));
                        lastDebriGenerateTime = Time.time;
                    }
                }
                else
                {
                    Debug.Log("Something collided with something it should not " + GetComponent <Collider>().name);
                }
            }
            else
            {
                lr.SetPosition(1, lrAim.position);
                laserEffectEnd.position = lrAim.position;
            }
        }
        else if (!isLaserCharging)
        {
            isLaserCharging = true;
            lr.enabled      = false;
            laserEffectEnd.gameObject.SetActive(false);
            laserEffectStart.gameObject.SetActive(false);
            StartCoroutine(LaserStarter());
        }
    }