Inheritance: MonoBehaviour
示例#1
0
    IEnumerator fireArrow(Vector3 towards)
    {
        this.elapsed       = 0;
        this.untilUnlocked = this.arrowDelay;
        this.locked        = true;

        yield return(new WaitForSeconds(arrowAnimationDelay));

        GameObject weapon = Instantiate(this.arrow,
                                        this.transform.position + new Vector3(0f, 0f, .1f),
                                        Quaternion.identity) as GameObject;

        weapon.GetComponent <Ouch> ().spawner = this.transform;

        Vector3 dir   = towards - this.transform.position;
        float   angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;

        weapon.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

        if (this.gameObject.tag == "Player")
        {
            PlayerController.instance.arrows--;
        }

        Ouch ouch = weapon.GetComponent <Ouch> ();

        ouch.damage         = this.damage;
        ouch.tag            = this.tag;
        ouch.destroyOnTouch = true;
    }
示例#2
0
    private void CreateOuch(bool horizontal, int direction)
    {
        if (!this.locked)
        {
            Destroy(this.weapon);

            this.elapsed       = 0;
            this.untilUnlocked = this.delay;
            this.locked        = true;

            this.weapon                    = new GameObject();
            this.weapon.name               = "meleeWeapon";
            this.weapon.transform.parent   = this.gameObject.transform;
            this.weapon.transform.position = this.gameObject.transform.position;

            BoxCollider2D collider = this.weapon.AddComponent <BoxCollider2D> ();
            collider.isTrigger = true;

            Vector2 playerSize = this.Size;
            collider.size = playerSize;

            if (horizontal)
            {
                collider.size = new Vector2(collider.size.x * this.widthMultiplier, this.range);
                collider.transform.Translate(0, (playerSize.y / 2 + this.range / 2) * direction, 0);
            }
            else
            {
                collider.size = new Vector2(this.range, collider.size.y * this.widthMultiplier);
                collider.transform.Translate((playerSize.x / 2 + this.range / 2) * direction, 0, 0);
            }

            Ouch ouch = this.weapon.AddComponent <Ouch> ();
            ouch.damage = this.damage;
        }
    }