// Draws Gizmos when Camera is selected in scene editor to assist in targetable object placing void OnDrawGizmosSelected() { #if UNITY_EDITOR if (Debug.IsKeyActive("camera")) { foreach (GameObject target in allTargetables) { if (Vector3.Distance(this.target.position, target.transform.position) <= target.GetComponent <Targetable> ().range) { if (target.GetComponent <Targetable> ().isTargetable) { if (Vector3.Angle(this.transform.forward, target.transform.position - this.transform.position) <= screenTargetArea) { Gizmos.color = Color.green; Gizmos.DrawRay(target.transform.position, (this.transform.position - target.transform.position)); } else { Gizmos.color = Color.red; Gizmos.DrawRay(target.transform.position, (this.transform.position - target.transform.position)); } } else { Gizmos.color = Color.red; Gizmos.DrawRay(target.transform.position, (this.transform.position - target.transform.position)); } } } Gizmos.color = new Color(1, 1, 1, 0.5f); Gizmos.DrawSphere(this.target.position, targetingRange); } #endif }
void OnDrawGizmosSelected() { #if UNITY_EDITOR if (cam && Debug.IsKeyActive("player")) { /*float inputHor = InputManager.input.MoveHorizontalAxis (); * float inputVert = InputManager.input.MoveVerticalAxis (); * Vector3 forward = transform.position + cam.transform.forward; * forward = new Vector3 (forward.x, transform.position.y, forward.z); * forward = Vector3.Normalize (forward - transform.position); * Vector3 right = new Vector3 (forward.z, 0f, -forward.x); * * Vector3 moveDir = Vector3.Normalize((inputHor * right) + (inputVert * forward)); * * Vector3 testMoveVect = Vector3.Lerp(moveVector, moveDir, 0.2f); * testMoveVect = new Vector3(testMoveVect.x, 0f, testMoveVect.z);*/ if (Input.GetKey(KeyCode.E)) { Gizmos.DrawSphere(transform.position + charCont.center, 1.5f); } } #endif }
/* * The bulk of PoP's 3rd person camera controllers implementation. * Determines whether camera should be in an event, behind player, or in targeting mode. * Tracks mouse and player position at the end of the frame for use during frame. */ void FixedUpdate() { #if UNITY_EDITOR /** Swap material color of targeted objects to debug targeting **/ if (Debug.IsKeyActive("camera")) { foreach (GameObject go in allTargetables) { go.GetComponent <Renderer>().material.SetColor("_Color", Color.red); } } #endif switch (_curState) { /*** Normal Camera Behavior ***/ case CameraState.Normal: targetLookAt = player.position; #if UNITY_EDITOR if (!Input.GetKey(KeyCode.LeftShift)) { HandleMouseInput(); } #else HandleMouseInput(); #endif var count = 0; do { CalculateDesiredPosition(); count++; } while (CheckifOccluded(count)); UpdatePosition(); break; /****************************/ /*** Target Lock Behavior ***/ case CameraState.TargetLock: if (targetedObjects.Count == 0f) { // Attempt to get targets, if no targets found break out targetedObjects = AcquireTarget(); if (targetedObjects.Count == 0) { _curState = CameraState.TargetReset; break; } } RaycastHit hit; Physics.Raycast(transform.position, (targetedObjects[targetindex].transform.position - transform.position), out hit); if (hit.collider.name != targetedObjects[targetindex].GetComponent <Collider>().name) { targetResetTimer -= Time.deltaTime; } else { targetResetTimer = 3f; } TargetLockCamera(targetindex); if (targetResetTimer <= 0f) { _curState = CameraState.TargetReset; } else { UpdatePosition(); } #if UNITY_EDITOR /** Color target green for debug purposes **/ if (Debug.IsKeyActive("camera")) { targetedObjects[targetindex].GetComponent <Renderer>().material.color = Color.green; } #endif break; /***********************/ /*** Reset Targeting ***/ case CameraState.TargetReset: TargetReset(); CalculateDesiredPosition(); UpdatePosition(); Quaternion rotation = Quaternion.LookRotation(targetLookAt - transform.position); if (transform.rotation == rotation) { _curState = CameraState.Normal; } break; /***********************/ /*** Camera Event ***/ case CameraState.CamEvent: eventTrigger.Event(); break; /********************/ /*** Paused State ***/ case CameraState.Pause: UpdatePosition(); break; /********************/ } mousePosition = Input.mousePosition; }