Esempio n. 1
0
    void Update()
    {
        grounded   = Physics2D.Linecast(transform.position, down_bump.position, 1 << LayerMask.NameToLayer("World") | 1 << LayerMask.NameToLayer("OneWayBlock"));
        JumpButton = Input.GetKeyDown(KeyCode.UpArrow);

        Vector3 tmpv3 = transform.position;

        if (tmpVector3.x < 0)
        {
            tmpv3.x = tmpv3.x - 1.7f;
        }
        else
        {
            tmpv3.x = tmpv3.x + 1.7f;
        }

        //Debug.DrawLine(transform.position, tmpv3, Color.red);
        Debug.DrawLine(transform.position, down_bump.position);


        if (Input.GetKeyDown(KeyCode.Space) && !Shoot && grounded)
        {
            Shoot = true;
            animator.Play("shoot");
            RaycastHit2D hit;
            if (hit = Physics2D.Linecast(transform.position, tmpv3, 1 << LayerMask.NameToLayer("Monster")))
            {
                hit.transform.GetComponent <zombie>().HP--;
            }
            direction = Directions.NONE;
            shootSound.Play();
        }

        if (grounded && JumpButton && !Shoot)
        {
            rigidbody2D.AddForce(new Vector2(0f, 220));
            jumpStart.Play();
        }

        if (rigidbody2D.velocity.x > MaxSpeed)
        {
            Vector2 newVelocity = rigidbody2D.velocity;
            newVelocity.x        = MaxSpeed;
            rigidbody2D.velocity = newVelocity;
        }

        if (rigidbody2D.velocity.x < -MaxSpeed)
        {
            Vector2 newVelocity = rigidbody2D.velocity;
            newVelocity.x        = -MaxSpeed;
            rigidbody2D.velocity = newVelocity;
        }

        if (!Shoot)
        {
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                tmpVector3           = transform.localScale;
                tmpVector3.x         = -1;
                transform.localScale = tmpVector3;
                direction            = Directions.LEFT;
            }
            else
            {
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    tmpVector3           = transform.localScale;
                    tmpVector3.x         = 1;
                    transform.localScale = tmpVector3;
                    direction            = Directions.RIGHT;
                }
                else
                {
                    direction = Directions.NONE;
                }
            }
        }
    }
Esempio n. 2
0
    void Update()
    {
        grounded = Physics2D.Linecast(transform.position, down_bump.position, 1 << LayerMask.NameToLayer("World") | 1 << LayerMask.NameToLayer("OneWayBlock"));
        JumpButton=Input.GetKeyDown (KeyCode.UpArrow);

        Vector3 tmpv3 = transform.position;

        if (tmpVector3.x < 0)
        {
            tmpv3.x = tmpv3.x - 1.7f;
        }
        else
        {
            tmpv3.x = tmpv3.x + 1.7f;
        }

        //Debug.DrawLine(transform.position, tmpv3, Color.red);
        Debug.DrawLine(transform.position, down_bump.position);

        if (Input.GetKeyDown(KeyCode.Space) && !Shoot && grounded)
        {
            Shoot = true;
            animator.Play("shoot");
            RaycastHit2D hit;
            if (hit=Physics2D.Linecast(transform.position, tmpv3, 1 << LayerMask.NameToLayer("Monster")))
            {
                hit.transform.GetComponent<zombie>().HP--;
            }
            direction = Directions.NONE;
            shootSound.Play();
        }

        if (grounded && JumpButton && !Shoot)
        {
            rigidbody2D.AddForce(new Vector2(0f, 220));
            jumpStart.Play();
        }

        if (rigidbody2D.velocity.x > MaxSpeed) {
            Vector2 newVelocity = rigidbody2D.velocity;
            newVelocity.x = MaxSpeed;
            rigidbody2D.velocity = newVelocity;
        }

        if (rigidbody2D.velocity.x < -MaxSpeed) {
            Vector2 newVelocity = rigidbody2D.velocity;
            newVelocity.x = -MaxSpeed;
            rigidbody2D.velocity = newVelocity;
        }

        if (!Shoot)
        {
            if (Input.GetKey(KeyCode.LeftArrow))
            {
                tmpVector3 = transform.localScale;
                tmpVector3.x = -1;
                transform.localScale = tmpVector3;
                direction = Directions.LEFT;
            }
            else
            {
                if (Input.GetKey(KeyCode.RightArrow))
                {
                    tmpVector3 = transform.localScale;
                    tmpVector3.x = 1;
                    transform.localScale = tmpVector3;
                    direction = Directions.RIGHT;
                }
                else
                {
                    direction = Directions.NONE;
                }
            }
        }
    }