コード例 #1
0
    void OnTriggerStay2D(Collider2D coll)
    {
        //Debug.Log ("Collide Stay!");
        stone_script stone = coll.gameObject.GetComponent <stone_script> ();

        if (stone != null)
        {
            if (isClick == true)
            {
                isCollide = true;
            }
        }
    }
コード例 #2
0
    void OnTriggerEnter2D(Collider2D coll)
    {
        ShotScript shot = coll.gameObject.GetComponent <ShotScript> ();

        if (shot != null)
        {
            return;
        }

        stone_script stone = coll.gameObject.GetComponent <stone_script> ();

        /*unitStatScript collStats = coll.gameObject.GetComponent<unitStatScript> ();
         * hexMove hexColl = coll.gameObject.GetComponent<hexMove> ();*/
        if (stone != null)
        {
            //Debug.Log ("Collide!");
            if (isClick == true)
            {
                isCollide = true;
            }

            if (isClick == true && isInitCollide == false)
            {
                float x1 = this.transform.position.x;
                float y1 = this.transform.position.y;
                float z1 = this.transform.position.z;
                //Debug.Log ("z= " + z1);
                this.transform.position = new Vector3(x1, y1, z1 + 20);                 //0
                isInitCollide           = true;
            }
        }

        /*if ((collStats != null || hexColl != null) && isGreen) {
         *      //Debug.Log ("Collide!");
         *      if (isClick == true) {
         *              isCollide = true;
         *
         *      }
         *
         *      if (isClick == true && isInitCollide == false) {
         *              float x1 = this.transform.position.x;
         *              float y1 = this.transform.position.y;
         *              float z1 = this.transform.position.z;
         *              //Debug.Log ("z= " + z1);
         *              this.transform.position = new Vector3 (x1, y1, z1 + 20);//0
         *              isInitCollide = true;
         *      }
         * }*/
    }
コード例 #3
0
ファイル: ShotScript.cs プロジェクト: khhle/Stalingrad
    void OnTriggerEnter2D(Collider2D otherCollider)
    {
        stone_script stone = otherCollider.gameObject.GetComponent <stone_script> ();

        if (stone != null)
        {
            //Debug.Log ("Collide stone!");
            SpecialEffectsHelper.Instance.Explosion(transform.position);
            Destroy(gameObject);
        }
        //this is where the damage calculations take place. otherStats is the enemy unit's stats
        //unitStatScript otherStats = otherCollider.gameObject.GetComponent<unitStatScript> ();
        hexMove otherHexMove = otherCollider.gameObject.GetComponent <hexMove> ();

        if (otherHexMove != null)
        {
            unitStatScript otherStats = otherHexMove.transform.parent.GetComponent <unitStatScript> ();
            if (otherStats != null && otherStats.playerOwner == 1 && teamNumber == 2)
            {
                if ((otherStats.isTank && parentsStats.canShootTank) || (otherStats.isPlane && parentsStats.canShootPlane) ||
                    (otherStats.isInfantry && parentsStats.canShootInfantry))
                {
                    //deals damage equal to this attack power minus arandom value of defense.
                    int tempDefense = Random.Range(0, otherStats.defense);
                    if (attackPower > tempDefense)
                    {
                        damageDealt = attackPower - tempDefense;
                        otherStats.statText.color = Color.red;
                        otherStats.health        -= damageDealt;
                    }
                    SpecialEffectsHelper.Instance.Explosion(transform.position);
                    if (!isCounter)
                    {
                        counterAttack(otherStats);
                    }



                    if (isSplash == true)
                    {
                        StartCoroutine(waitAndCall());
                    }
                    else
                    {
                        Destroy(gameObject);
                    }
                }
            }
            else if (otherStats != null && otherStats.playerOwner == 2 && teamNumber == 1)
            {
                if ((otherStats.isTank && parentsStats.canShootTank) || (otherStats.isPlane && parentsStats.canShootPlane) ||
                    (otherStats.isInfantry && parentsStats.canShootInfantry))
                {
                    //deals damage equal to this attack power minus arandom value of defense.
                    int tempDefense = Random.Range(0, otherStats.defense);
                    if (attackPower > tempDefense)
                    {
                        damageDealt = attackPower - tempDefense;
                        otherStats.statText.color = Color.red;
                        otherStats.health        -= damageDealt;
                    }
                    SpecialEffectsHelper.Instance.Explosion(transform.position);
                    if (!isCounter)
                    {
                        counterAttack(otherStats);
                    }


                    if (isSplash == true)
                    {
                        StartCoroutine(waitAndCall());
                    }
                    else
                    {
                        Destroy(gameObject);
                    }
                }
            }
        }
    }