에셋에 포함되어있던 유용한 소스 : 타겟을 중점으로 마우스 회전하며 볼 수 있는 스크립트
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | using UnityEngine; using System.Collections; public class CameraOrbit : MonoBehaviour { public Transform target; public float distance = 2f; public float lerpSpeed = 3f; public bool raycastedDistance = false; float wdist, cdist; Vector3 wrot, crot; Vector3 worigin, corigin; void Start () { wdist = distance; } void Update () { float t = Time.deltaTime * 2f * lerpSpeed; wdist -= Input.GetAxis( "Mouse ScrollWheel" ) * Time.deltaTime * 200f; cdist = Mathf.Lerp( cdist , wdist , t ); if ( Input.GetMouseButton( 1 ) ) { wrot.y += Input.GetAxis( "Mouse X" ) * 3f; wrot.x -= Input.GetAxis( "Mouse Y" ) * 3f; } wrot.z = 0f; crot.x = Mathf.LerpAngle( crot.x , wrot.x , t ); crot.y = Mathf.LerpAngle( crot.y , wrot.y , t ); crot.z = Mathf.LerpAngle( crot.z , wrot.z , t ); transform.rotation = Quaternion.Euler( crot ); if ( target != null ) worigin = target.position; else worigin = Vector3.zero; if ( raycastedDistance ) { RaycastHit h; Ray r = new Ray( worigin - transform.forward * ( cdist + 1f ) , transform.forward ); if(Physics.Raycast(r,out h)) { worigin = h.point; } } corigin = Vector3.Lerp( corigin , worigin , t ); transform.position = corigin - transform.forward * cdist; } void OnDrawGizmosSelected () { Gizmos.color = Color.red; Gizmos.DrawWireSphere( worigin , 0.2f ); Gizmos.DrawLine( worigin , transform.position ); Gizmos.color = Color.blue; Gizmos.DrawWireSphere( corigin , 0.2f ); Gizmos.DrawLine( corigin , transform.position ); } } | cs |
'NOTE > SaveSource' 카테고리의 다른 글
[Save Source] UIResult (0) | 2017.01.26 |
---|---|
[SaveSource] StageRankManager (0) | 2017.01.20 |
[SaveSource] WaveMoveTrigger (0) | 2017.01.12 |
[SaveSource] SpeicalWeapon (0) | 2017.01.12 |
[SaveSource] WeaponDrob (0) | 2017.01.04 |