Last active
April 9, 2018 09:51
-
-
Save todorok1/582084a727850cdb63c2b2d3e31707b3 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 () { | |
} | |
// Update is called once per frame | |
void Update () { | |
// Input.GetKeyUpはキーが一度押された後、それが離された時にTrueを返す | |
// KeyCode.Spaceはスペースキーを表す | |
if (Input.GetKeyUp(KeyCode.Space)){ | |
// ボールを飛ばす処理をStart()からここに移動させる | |
// 力を加える方向 | |
Vector3 forceDirection = new Vector3(1.0f, 1.0f, 0f); | |
// 加える力の大きさ | |
float forceMagnitude = 10.0f; | |
// 向きと力の計算 | |
Vector3 force = forceMagnitude * forceDirection; | |
// SphereオブジェクトのRigidbodyコンポーネントへの参照を取得 | |
Rigidbody rb = gameObject.GetComponent<Rigidbody>(); | |
// 力を加えるメソッド | |
rb.AddForce(force, ForceMode.Impulse); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment