Last active
October 11, 2018 00:50
-
-
Save aidiary/b9600d04c6654eaa8c07 to your computer and use it in GitHub Desktop.
大砲から砲弾を発射する
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
#pragma strict | |
// 砲弾に加える力 | |
var power : float = 30000; | |
// 砲弾オブジェクト(インスペクタからセット) | |
var shellObject : GameObject; | |
// 発射音(インスペクタからセット) | |
var bomb : AudioClip; | |
function Update () { | |
if (Input.GetMouseButtonDown(0)) { | |
// メインカメラから見たマウスの方向を取得 | |
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
var dir : Vector3 = ray.direction.normalized; | |
// 砲弾を作成 | |
var shell = Instantiate(shellObject, transform.position, transform.rotation); | |
// マウスの方向へ力を加えて発射 | |
shell.rigidbody.AddForce(dir * power, ForceMode.Impulse); | |
// 発射音を再生 | |
audio.PlayOneShot(bomb); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment