LoginSignup
4
4

More than 5 years have passed since last update.

GetComponent<Rigidbody>().velocityと書くのが面倒な時

Posted at

オブジェクトにアタッチしたRigidbodyのvelocityを取得するときはGetComponent<Rigidbody>().velocityと書きますが、冗長ですよね。

そんな時は、こう書くとスッキリして良いかも。


Vector3 velocity{
    get{
        return GetComponent<Rigidbody>().velocity;
    }
    set{
        GetComponent<Rigidbody>().velocity = value;
    }
}

参考
プロパティ - C# によるプログラミング入門 | ++C++; // 未確認飛行 C

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4