Пример #1
0
    void Start()
    {
        //origin = origin + new Vector2(attack.offset.x * direction, attack.offset.y);
        attackPath = attack.attackPath;

        if (attack.targetType == Attack.TargetType.TargetStraight)
        {
            RaycastHit2D hitInfo;
            hitInfo = Physics2D.Raycast(transform.position, Vector2.right, attack.offset.x);

            if (hitInfo.collider.gameObject.tag == "Enemy")
            {
                //transform.position = hitInfo.collider.gameObject.transform.position;
            }
            else
            {
                //transform.position = origin;
            }
        }
        else
        {
            print(origin);
            //transform.position = origin;
        }


        gameObject.tag = "Attack";

        rb              = gameObject.AddComponent <Rigidbody2D>();
        rb.constraints  = RigidbodyConstraints2D.FreezeRotation;
        rb.gravityScale = 0;

        sr = attack.spriteAnimation.GetComponent <SpriteRenderer>();

        velocityDiv = attack.velocityDiv;
        lifetime    = attack.lifetime;
        xSpeed      = attack.speed;

        if (attack.attackType == Attack.AttackType.Melee)
        {
            //mht = sprite
        }

        if (attack.bounces)
        {
            lifetime *= attack.bounceCount + 1;
        }


        if (boxCol = GetComponentInChildren <BoxCollider2D>())
        {
            print("Box Collider Present");
        }

        if (attack.spriteAnimation != null)
        {
            GameObject sprite = Instantiate(attack.spriteAnimation, transform.position, Quaternion.identity, this.gameObject.transform);
            if (direction < 0)
            {
                // facing left
                sprite.transform.localScale = MathC.MultiplyVector(sprite.transform.localScale, MathC.NegaVectorX);
            }

            if (attack.attackBase != null)
            {
                // Checks for a 2D Collider in the attack base prefab
                if (sprite.GetComponent <Collider2D>())
                {
                    // Adds the attack collision script and links the attack script to it
                    AttackCollision _ac = sprite.AddComponent <AttackCollision>();
                    _ac._as = this;
                }
            }

            if (attack.attackPath == Attack.AttackPath.Meteor)
            {
                sprite.transform.Rotate(new Vector3(0, 0, -45));
                ySpeed = xSpeed;
            }
            else if (attack.attackPath == Attack.AttackPath.CrashDown)
            {
                sprite.transform.Rotate(new Vector3(0, 0, -90));
                ySpeed = xSpeed;
            }
        }



        if (col != null)
        {
            col.isTrigger = true;
        }

        if (attack.attackType == Attack.AttackType.Beam)
        {
            if (boxCol == null)
            {
                boxCol = attack.spriteAnimation.GetComponent <BoxCollider2D>();
            }

            if (boxCol != null)
            {
                boxCol.isTrigger = true;
                sr.tileMode      = SpriteTileMode.Continuous;
            }
            else
            {
                Debug.LogError("No Box Collider Present on Beam");
            }
        }
    }