void Update() { if (GameManager.gameState == GameManager.GameState.Playing || GameManager.gameState == GameManager.GameState.OnConveyor) { myFaceDirection = (input.x > 0 ? faceDirection.Right : input.y > 0 ? faceDirection.Up : input.x < 0 ? faceDirection.Left : input.y < 0 ? faceDirection.Down : myFaceDirection); myRigidBody.velocity = Vector3.MoveTowards(myRigidBody.velocity, (Vector3)(input * speed), 50 * Time.deltaTime); } else { myRigidBody.velocity = Vector2.zero; } }
IEnumerator waiter(faceDirection d) { if (d == faceDirection.forward || d == faceDirection.backward) { face.transform.Translate(speed * Time.deltaTime, 0, 0); yield return(new WaitForSeconds(1.0f)); face.transform.Translate(-(speed * Time.deltaTime), 0, 0); yield return(new WaitForSeconds(1.0f)); } else { face.transform.Translate(0, speed * Time.deltaTime, 0); yield return(new WaitForSeconds(1.0f)); face.transform.Translate(0, -(speed * Time.deltaTime), 0); yield return(new WaitForSeconds(1.0f)); } }
// Update is called once per frame void Update() { if (face.transform.rotation.y > 315f || face.transform.rotation.y <= 45f) { direction = faceDirection.forward; } else if (face.transform.rotation.y > 45f || face.transform.rotation.y <= 135f) { direction = faceDirection.right; } else if (face.transform.rotation.y > 135f || face.transform.rotation.y <= 225f) { direction = faceDirection.backward; } else { direction = faceDirection.left; } StartCoroutine(waiter(direction)); }
public void RotateClockWise() { switch (myFaceDirection) { case faceDirection.Down: myFaceDirection = faceDirection.Left; break; case faceDirection.Left: myFaceDirection = faceDirection.Up; break; case faceDirection.Up: myFaceDirection = faceDirection.Right; break; case faceDirection.Right: myFaceDirection = faceDirection.Down; break; default: break; } }
void Update() { if (isDead) { return; } if (Input.GetKeyUp(KeyCode.E)) { animator.SetBool("isHacking", false); } if (Input.GetKey(KeyCode.E) && animator.GetBool("isHacking")) { return; } //float xInput = Input.GetAxis("Horizontal"); //float yInput = Input.GetAxis("Vertical"); //animator.SetFloat("Speed", Mathf.Abs(xInput+yInput)); Vector2 positionOnScreen = Camera.main.WorldToViewportPoint(transform.position); Vector2 mouseOnScreen = (Vector2)Camera.main.ScreenToViewportPoint(Input.mousePosition); float angle = GetAngle(positionOnScreen, mouseOnScreen); Vector3 direction = new Vector3(); if (Input.GetKey(KeyCode.A)) // left { direction += Vector3.left * speed * Time.deltaTime; currentDir = faceDirection.Left; } if (Input.GetKey(KeyCode.D)) // right { direction += Vector3.right * speed * Time.deltaTime; currentDir = faceDirection.Right; } if (Input.GetKey(KeyCode.W)) // forward { var rotation = Quaternion.Euler(new Vector3(0f, 0f, angle + 90)); direction += rotation * Vector3.up * speed * Time.deltaTime; currentDir = faceDirection.Up; } if (Input.GetKey(KeyCode.S)) // backward { direction += Vector3.down * speed * Time.deltaTime; currentDir = faceDirection.Down; } direction.x = Mathf.Clamp(direction.x, -1 * speed * Time.deltaTime, 1 * speed * Time.deltaTime); direction.y = Mathf.Clamp(direction.y, -1 * speed * Time.deltaTime, 1 * speed * Time.deltaTime); Debug.Log(direction.y); transform.position += direction; if (direction.x != 0 || direction.y != 0) { animator.SetBool("isMoving", true); } else { animator.SetBool("isMoving", false); } }