Example #1
0
    protected void Shoot(GunIns gun)
    {
        Vector3 mousePositionInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        Vector3 mousePositionInScene = Vector3.Scale(mousePositionInWorld, forwardZero);
        Vector3 toMousePosition      = mousePositionInScene - transform.position;

        if (toMousePosition.x * transform.right.x < 0)
        {
            transform.right *= -1;
        }

        gun.Use(transform);
        myAni.SetTrigger("Shoot");
        isShootAnimPlaying = true;
        ////假如现有武器冷却完毕
        //if (currentWeapon.IsColdDown())
        //{
        //    //重新开始冷却计时!!!
        //    //timer = 0;

        //    //开火点对象显示开火火花
        //    firePoint.gameObject.SetActive(true);
        //    //播放射击动画
        //    myAni.SetTrigger("Shoot");
        //    //产生子弹

        //    Collider2D[] enemys = Physics2D.OverlapCircleAll(transform.position, 5f);
        //    for (int i = 0; i < enemys.Length; i++)
        //    {
        //        if (enemys[i].gameObject.tag == "enemy")
        //        {
        //            enemy = enemys[i].gameObject;
        //            break;
        //        }
        //    }


        //    if (enemy != null)
        //    {
        //        currentWeapon.Aim(enemy.transform.position);
        //        currentWeapon.Fire(firePoint);
        //    }
        //    else
        //    {
        //        Vector3 v = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        //        v = Vector3.Scale(v, Vector3.right + Vector3.up);
        //        currentWeapon.Aim(v);
        //        currentWeapon.Fire(firePoint);
        //    }
        //}
    }
Example #2
0
    void Update()
    {
        isGround = CheckGround();

        float horizontal = Input.GetAxis("Horizontal");
        float vertical   = Input.GetAxis("Vertical");

        if (isFly && vertical > 0.5f)
        {
            isFlying = true;
        }
        if (isGround)
        {
            currentJump = 2;
            Debug.Log("跳跃可以吗?0");
            myAni.SetBool("Jump", false);
        }
        if (Input.GetKeyDown(KeyCode.J))
        {
            myAni.SetBool("Jump", true);
            Debug.Log("跳跃可以吗?1");
            if (currentJump >= 1)
            {
                body.velocity = Vector2.up * jump + body.velocity.x * Vector2.right;
                //此时我的为Jump的动画为true

                //currentJump变量减一次
                Debug.Log("跳跃可以吗?2");
                currentJump--;
            }
        }
        if (horizontal != 0 || vertical != 0)
        {
            //则让移动的动画设为true
            Debug.Log("跳跃可以吗?3");
            myAni.SetBool("Move", true);
            //如果枪的值为空,则枪的变量为 子对象的位置
            //if (gun == null)
            //    gun = transform.GetChild(0).gameObject;

            //if (gun.activeSelf)
            //    gun.SetActive(false);
            //如果(horizontal< 0则执行水平位置向左
            if (horizontal < 0)
            {
                Debug.Log("跳跃可以吗?4");
                transform.right = Vector3.left;
            }
            //否则(horizontal< 0则执行水平位置向右
            else
            {
                Debug.Log("跳跃可以吗?5");
                transform.right = Vector3.right;
            }
            //如果飞行 则 执行body力的速率是 水平向右*x轴方向操作*移动速度+水平向上*y轴方向操作*移动速度
            if (isFly && isFlying)
            {
                body.velocity = Vector2.right * horizontal * moveSpeed + Vector2.up * vertical * moveSpeed;
            }
            //否则body速率向为水平向上*y轴方向操作*移动速度的 力为0
            else
            {
                body.velocity = Vector2.right * horizontal * moveSpeed + body.velocity.y * Vector2.up;
            }
            //myRender.flipX = horizontal < 0;
        }
        //否则 执行 我的动画为MOVE的组件 为false
        else
        {
            myAni.SetBool("Move", false);
        }

        if (Input.GetKeyDown(KeyCode.U))
        {
            isFlying          = true;
            body.gravityScale = 0;
        }

        //当按下I键则执行 isFlyin 为 false,而且body的重力比例为5
        if (Input.GetKeyDown(KeyCode.I))
        {
            isFlying          = false;
            body.gravityScale = 5;
        }

        //if (isGround && Input.GetMouseButton(1)) //鼠标左键 为0 鼠标右键为1
        if (isGround && Input.GetMouseButtonDown(1)) //鼠标左键 为0 鼠标右键为1
        {
            ColdWeapon coldWeapon = rightFistTrans.GetComponentInChildren <ColdWeapon>();
            if (coldWeapon != null)
            {
                Cut();
            }
        }

        if (isGround && Input.GetMouseButtonDown(0))
        {
            GunIns gun = leftFistTrans.GetComponentInChildren <GunIns>();
            if (gun != null && !isShootAnimPlaying && gun.canShoot)
            {
                Shoot(gun);
            }
        }
        timer += Time.deltaTime;
    }