Skip to content

Instantly share code, notes, and snippets.

@dskjal
Last active September 22, 2016 21:05
Show Gist options
  • Select an option

  • Save dskjal/dc1292bc5e78c9e3e7ad29d16efce931 to your computer and use it in GitHub Desktop.

Select an option

Save dskjal/dc1292bc5e78c9e3e7ad29d16efce931 to your computer and use it in GitHub Desktop.
Unity で弾痕を表示する
// 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