オブジェクトをくるくる回してみます。
インスペクターから回転速度を調整できるようにpublic としてspeedを定義します。
ステップはconst で定義しておきます。
左クリックを検出するために if (Input.GetMouseButton(0))します。
今回はUnity標準のrigidbodyを使わせていただきます。
角速度はアトリビュートangularVelocityに格納されているのでこれをいじります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Rotation2 : MonoBehaviour { public float speed = 1; const float df = 1f / 60f; void FixedUpdate() { //左クリックが押されたら if (Input.GetMouseButton(0)) { //リジッドボディを取得する Rigidbody rigidbody = GetComponent<Rigidbody>(); //角速度を定義する rigidbody.angularVelocity = new Vector3(0f, speed,0f); } } } |
The following two tabs change content below.
Keita N
最新記事 by Keita N (全て見る)
- Freenove ESP32-WROVER Board CAMを購入しました。その2 - 2023年11月4日
- Freenove ESP32-WROVER Board CAMを購入しました。 - 2023年11月4日
- ANOGAN 第一話 - 2023年6月16日