示例#1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        if (deathTimer == 0)
        {
            return;
        }

        bool destroyMe = false;

        TankCombat tc = collider.gameObject.GetComponent <TankCombat>();

        if (tc != null)
        {
            int side = GetHitSide(startPos, collider.gameObject.transform.position, collider.gameObject.transform.right);
            tc.GotHitByMissile(side, damage, team);
            destroyMe = true;
            //Debug.Log ("Angle: " + angle + " AngleDir: " + angleDir + " side: " + side);
        }

        Exploder ex = collider.gameObject.GetComponent <Exploder>();

        if (ex != null)
        {
            ex.Explode();
            PlayGame.singleton.AddBarrelScore();
            destroyMe = true;
        }

        // destroy missile
        if (destroyMe)
        {
            deathTimer = 0;
            NetworkServer.Destroy(this.gameObject);
        }
    }
示例#2
0
    void Update()
    {
        if (Time.time > timer)
        {
            transform.localScale *= 0.9f;
            timer  = Time.time + 0.1f;
            count += 1;
            if (count == 8)
            {
                GameObject.Destroy(gameObject);

                GameObject scorch = (GameObject)GameObject.Instantiate(scorchMark, transform.position, Quaternion.identity);
                GameObject.Destroy(scorch, 1);

                for (int i = 0; i < 3; i++)
                {
                    Vector3 pos = transform.position;
                    pos.x += UnityEngine.Random.Range(-10, 10) / 10.0f;
                    pos.y += UnityEngine.Random.Range(-10, 10) / 10.0f;
                    GameObject exp = (GameObject)GameObject.Instantiate(explosion, pos, Quaternion.identity);
                    GameObject.Destroy(exp, 1);
                }

                if (NetworkServer.active)
                {
                    Collider2D[] hits = Physics2D.OverlapCircleAll(transform.position, 2.0f);
                    foreach (var hit in hits)
                    {
                        TankCombat hitTc = hit.GetComponent <TankCombat>();
                        if (hitTc != null)
                        {
                            int side = Missile.GetHitSide(transform.position, hit.transform.position, hit.transform.right);
                            hitTc.GotHitByMissile(side, 50, team);
                        }
                    }
                }
            }
        }
    }