// Update is called once per frame void Update() { float x = Input.GetAxisRaw("Horizontal"); float y = Input.GetAxisRaw("Vertical"); float isMove = 0; Vector2 tempVector = new Vector2(x, y); if (tempVector.x != 0 || tempVector.y != 0) { lookDirection = tempVector; isMove = 1; } anim.SetFloat("moveX", lookDirection.x); anim.SetFloat("moveY", lookDirection.y); anim.SetFloat("speed", isMove); Vector2 position = rbody.position; //position.x += x*speed*Time.deltaTime; //position.y += y*speed*Time.deltaTime; position += tempVector * speed * Time.deltaTime; rbody.MovePosition(position); if (Input.GetKeyDown(KeyCode.J) && currentBulletNum > 0) { changeBulletNum(-1); GameObject bullet = Instantiate(bulletpreab, rbody.position, Quaternion.identity); BulletController bc = bullet.GetComponent <BulletController>(); if (bc != null) { bc.Move(lookDirection, 300); } AudioManager.instance.AudioPlay(launchclip); } if (Input.GetKeyDown(KeyCode.F)) { RaycastHit2D hit = Physics2D.Raycast(rbody.position, lookDirection, 2f, LayerMask.GetMask("NPC")); if (hit.collider != null) { NpcController nc = hit.collider.GetComponent <NpcController>(); if (nc != null) { nc.ShowDialog(); } Debug.Log("玩家与NPC交互"); } } //无敌倒计时 if (isInvisible) { invisibleTimer -= Time.deltaTime; if (invisibleTimer < 0) { isInvisible = false; } } }