Skip to content

Instantly share code, notes, and snippets.

@vend9520
Created September 18, 2016 19:03
Show Gist options
  • Select an option

  • Save vend9520/8ab869cdd5b24d21d294ce81b993767f to your computer and use it in GitHub Desktop.

Select an option

Save vend9520/8ab869cdd5b24d21d294ce81b993767f to your computer and use it in GitHub Desktop.
DOF使用時に選択したオブジェクトへフォーカスを当てる
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