Last active
September 22, 2016 21:05
-
-
Save dskjal/dc1292bc5e78c9e3e7ad29d16efce931 to your computer and use it in GitHub Desktop.
Unity で弾痕を表示する
This file contains hidden or 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
| // BEGIN MIT LICENSE BLOCK // | |
| // | |
| // Copyright (c) 2016 dskjal | |
| // This software is released under the MIT License. | |
| // http://opensource.org/licenses/mit-license.php | |
| // | |
| // END MIT LICENSE BLOCK // | |
| using UnityEngine; | |
| public class FpvCamera : MonoBehaviour { | |
| public GameObject bulletHole; | |
| void Awake() { | |
| // プレハブのロード.インスペクタから設定してもよい | |
| bulletHole = Resources.Load<GameObject>("bullet hole"); | |
| } | |
| void Update () { | |
| if (Input.GetButtonDown("Fire1")) { | |
| // 弾痕のヒット判定 | |
| RaycastHit hitInfo; | |
| if (Physics.Raycast(transform.position, transform.forward, out hitInfo, 100f)) { | |
| // ヒット位置に配置するとちらつく | |
| var decalPos = hitInfo.point + hitInfo.normal * 0.01f; | |
| var decalRot = Quaternion.FromToRotation(-bulletHole.transform.forward, hitInfo.normal); | |
| Instantiate(bulletHole, decalPos, decalRot); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment