Skip to content

Instantly share code, notes, and snippets.

@tomazsaraiva
Last active February 17, 2018 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomazsaraiva/b4973883117b415b9ed0a150a6e9ac06 to your computer and use it in GitHub Desktop.
Save tomazsaraiva/b4973883117b415b9ed0a150a6e9ac06 to your computer and use it in GitHub Desktop.
Vector2 screenCenterPoint = new Vector2(Screen.width/2, Screen.height/2);
_ray = Camera.main.ScreenPointToRay(screenCenterPoint);
if(Physics.Raycast(_ray, out _hit, Camera.main.farClipPlane) && _bulletHole != null)
{
Vector3 bulletHolePosition = _hit.point + _hit.normal * 0.01f;
Quaternion bulletHoleRotation = Quaternion.FromToRotation(-Vector3.forward, _hit.normal);
GameObject hole = GameObject.Instantiate(_bulletHole, bulletHolePosition, bulletHoleRotation);
hole.transform.SetParent(_hit.transform);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment