protected override void Update() { float gyroZ = ActionInput.GetJoyconGyro().z *moveSpeed *Time.deltaTime * 60f; foreach (Transform child in transform) { // 子要素の歯車を回転させる child.transform.Rotate(0f, 0f, -gyroZ * 20f); } if (Mathf.Abs(moveDistance + gyroZ) > moveDistanceMax) { gyroZ = (gyroZ > 0) ? moveDistanceMax - moveDistance : -(moveDistanceMax + moveDistance); } moveDistance += gyroZ; transform.position += new Vector3(gyroZ * Mathf.Cos(moveAngle), gyroZ * Mathf.Sin(moveAngle)); base.Update(); // 画面外にいるときは処理を行わないようにしたい 出来れば基底クラスで //画面内にいる時に音出す if (targetRenderer.isVisible && Mathf.Abs(ActionInput.GetJoyconGyro().z) > 0.1f) { if (!audioSource.isPlaying) { audioSource.Play(); } //フェードイン audioSource.volume += (1 - audioSource.volume) * 0.2f; //Debug.Log("歯車音:" + gyroZ); } else { //audioSource.Stop(); //フェードアウト audioSource.volume *= 0.9f; if (audioSource.volume < 0.01f) { audioSource.Stop(); } } }
// Update is called once per frame void Update() { //float vx = /* * float posX = transform.localPosition.x + -speed * Time.deltaTime; * posX = (posX + height * 16.0f / 9.0f) % (height * 16.0f / 9.0f); * float posY = transform.localPosition.y + speed * Time.deltaTime; * posY = (posY + height) % (height); * * transform.localPosition = new Vector2(posX, posY); */ float speed = ActionInput.GetJoyconGyro().z *initSpeed; float posX = transform.position.x - parentTrfm.position.x + -speed * 1.2f * Time.deltaTime; posX = (posX + width) % (width); float posY = transform.position.y - parentTrfm.position.y + speed * Time.deltaTime; posY = (posY + height) % (height); transform.position = new Vector2(posX + parentTrfm.position.x, posY + parentTrfm.position.y); }