関数2
関数2
移動に関係するもの
| 移動 | (物,方向,速度) |
| ローカル移動 | (物,方向,速度) |
| 瞬間移動 | (物,座標) |
| 移動FX | (物,方向,速度) |
| ローカル移動FX | (物,方向,速度) |
| 瞬間移動FX | (物,座標) |
using UnityEngine;
using UnityEngine.UI;
public static class 関数2
{
static public void 移動(GameObject A, Vector3 方向, float 速度=3)
{ A.transform.Translate(方向.normalized * 速度 * Time.deltaTime, Space.World); }
static public void ローカル移動(GameObject A, Vector3 方向, float 速度=3)
{ A.transform.Translate(方向.normalized * 速度 * Time.deltaTime); }
static public void 瞬間移動(GameObject A, Vector3 座標)
{ A.transform.position = 座標; }
static public void 移動FX(GameObject A, Vector3 方向, float 速度)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
Vector3 移動量 = 方向.normalized * 速度 * Time.fixedDeltaTime;
rb.MovePosition(rb.position + 移動量);
}
static public void ローカル移動FX(GameObject A, Vector3 方向, float 速度)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
Vector3 ローカル方向 = 方向.normalized;
Vector3 ワールド方向 = A.transform.TransformDirection(ローカル方向);
Vector3 移動量 = ワールド方向 * 速度 * Time.fixedDeltaTime;
rb.MovePosition(rb.position + 移動量);
}
static public void 瞬間移動FX(GameObject A, Vector3 方向)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
rb.MovePosition(方向);
}
static public void 速度移動FX(GameObject A, Vector3 方向, float 速度)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
rb.velocity = 方向.normalized * 速度;
}
static public void 追加速度移動FX(GameObject A, Vector3 方向, float 力)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
rb.AddForce(方向.normalized * 力, ForceMode.Impulse);
}
static public void 重力移動FX(GameObject A, Vector3 方向, float 力)
{
Rigidbody rb = A.GetComponent<Rigidbody>();
if (rb == null) { Debug.Log("Rigidbodyがないよ"); return; }
rb.AddForce(方向.normalized * 力, ForceMode.Force);
}
}
説明
重力移動FXは実際の重力と違い重さが重いと移動が下がる

