Last active
April 9, 2018 09:45
-
-
Save todorok1/0ddc46435deac8bf3e0dfa3564523637 to your computer and use it in GitHub Desktop.
Unityチュートリアル・斜方投射のスクリプト。
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 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