// Update is called once per frame void Update() { switch (spinst) { case SPINST.INIT: if (Input.GetMouseButtonDown(0)) { this.start = Input.mousePosition; } else if (Input.GetMouseButtonUp(0)) { Vector2 end = Input.mousePosition; float swipe = end.x - start.x; this.speed = swipe / 500.0f; // 効果音再生する GetComponent <AudioSource>().Play(); spinst = SPINST.WAIT; } break; case SPINST.WAIT: if (this.speed < 0.01f) { spinst = SPINST.RESULT; } break; case SPINST.RESULT: if (Input.GetMouseButtonUp(0)) { Vector3 pos = transform.position; pos.x = -7.0f; transform.SetPositionAndRotation(pos, Quaternion.identity); this.speed = 0.0f; spinst = SPINST.INIT; } break; } if (spinst < SPINST.RESULT) { transform.Translate(this.speed, 0.0f, 0.0f); this.speed *= 0.98f; } }
// Update is called once per frame void Update() { if (spinst == SPINST.INIT) { if (Input.GetMouseButtonDown(0)) { this.rotspd = -2.0f; spinst = SPINST.UP; } } else if (spinst == SPINST.UP) { this.rotspd *= 2.0f; if (this.rotspd < -32.0f) { this.rotspd = -32.0f; spinst = SPINST.WAIT; } } else if (spinst == SPINST.WAIT) { if (Input.GetMouseButtonDown(0)) { spinst = SPINST.DOWN; } } else if (spinst == SPINST.DOWN) { this.rotspd *= 0.98f; if (this.rotspd >= -0.1f) { this.rotspd = 0.0f; spinst = SPINST.RESULT; } } else if (spinst == SPINST.RESULT) { timer++; if (timer >= 20) { spinst = SPINST.INIT; } } transform.Rotate(0.0f, 0.0f, this.rotspd); }