オブジェクトをくるくる回してみます。
インスペクターから回転速度を調整できるように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 (全て見る)
- python : pyscript - 2022年5月16日
- python : logging モジュールの使い方 - 2022年5月16日
- 機械名:号機:顧客番号 - 2022年2月17日