Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unityチュートリアル・斜方投射のスクリプト。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SphereBooster : MonoBehaviour {
// Use this for initialization
void Start () {
// 力を加える向きをVector3型で定義
// 今回はX軸から45度の向きに射出するため、XとYを1:1にする
Vector3 forceDirection = new Vector3(1.0f, 1.0f, 0f);
// 上の向きに加わる力の大きさを定義
float forceMagnitude = 10.0f;
// 向きと大きさからSphereに加わる力を計算する
Vector3 force = forceMagnitude * forceDirection;
// SphereオブジェクトのRigidbodyコンポーネントへの参照を取得
Rigidbody rb = gameObject.GetComponent<Rigidbody>();
// 力を加えるメソッド
// ForceMode.Impulseは撃力
rb.AddForce(force, ForceMode.Impulse);
}
// Update is called once per frame
void Update () {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.