Last active
August 29, 2015 13:59
-
-
Save tsubaki/10831265 to your computer and use it in GitHub Desktop.
rigidbodyをkinematicにする例(別コンポーネントとの連携)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class FreezRigidbody : MonoBehaviour | |
{ | |
Rigidbody _rigidbody; | |
// 定義しておくとコンポーネント起動時に1回呼ばれるイベント。詳しくはMonoBehaviour参照 | |
void Start () | |
{ | |
// ゲームオブジェクトに付いてる他のコンポーネント(今回はRigidbody)を取得 | |
_rigidbody = GetComponent<Rigidbody> (); | |
} | |
// 定義しておくと毎フレーム呼ばれるイベント | |
void Update () | |
{ | |
// キーボード入力取得 | |
if (Input.GetKeyDown (KeyCode.Space)) { | |
// isKinematicをtrueに | |
_rigidbody.isKinematic = true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rigidbodyを付けたコンポーネントに付けて実行。スペースキーを押すとkinematicがtrueになるようになる。