Created
September 18, 2016 19:03
-
-
Save vend9520/8ab869cdd5b24d21d294ce81b993767f to your computer and use it in GitHub Desktop.
DOF使用時に選択したオブジェクトへフォーカスを当てる
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
| using UnityEngine; | |
| using System.Collections; | |
| using UnityStandardAssets.ImageEffects; | |
| public class TapFocus : MonoBehaviour { | |
| void Update () { | |
| if (Input.GetMouseButton(0)) { | |
| //レイを生成 | |
| Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); | |
| RaycastHit hit = new RaycastHit(); | |
| if (Physics.Raycast(ray, out hit)) { | |
| //カメラと対象オブジェクトの距離を測るため、それぞれの位置を取得 | |
| Vector3 position1 = Camera.main.transform.position; | |
| Vector3 position2 = hit.point; | |
| float distance = Vector3.Distance(position1, position2); | |
| //メインカメラにアタッチした被写界深度スクリプトのフォーカス距離を変更する | |
| Camera.main.GetComponent<DepthOfField>().focalLength = distance; | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment