private void OnTriggerEnter2D(Collider2D collision)
    {
        ColdWeapon coldWeapon = transform.parent.GetComponentInChildren <ColdWeapon>();

        if (coldWeapon != null)
        {
            EventManager.ExecuteEvent("ColdWeaponHurt", collision);
        }
    }
Ejemplo n.º 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;
    }