Advertisement
Guest User

Untitled

a guest
Nov 21st, 2017
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. namespace Cinemachine.Examples
  4. {
  5.  
  6. public class ScriptingExample : MonoBehaviour
  7. {
  8. CinemachineVirtualCamera vcam;
  9. CinemachineFreeLook freelook;
  10.  
  11. void Start()
  12. {
  13. // Create a Cinemachine brain on the main camera
  14. var brain = GameObject.Find("Main Camera").AddComponent<CinemachineBrain>();
  15. brain.m_ShowDebugText = true;
  16. brain.m_DefaultBlend.m_Time = 1;
  17.  
  18. // Create a virtual camera that looks at object "Cube", and set some settings
  19. vcam = new GameObject("VirtualCamera").AddComponent<CinemachineVirtualCamera>();
  20. vcam.m_LookAt = GameObject.Find("Cube").transform;
  21. vcam.m_Priority = 10;
  22. vcam.gameObject.transform.position = new Vector3(0, 1, 0);
  23.  
  24. // Install a composer. You can install whatever CinemachineComponents you need,
  25. // including your own custom-authored Cinemachine components.
  26. var composer = vcam.AddCinemachineComponent<CinemachineComposer>();
  27. composer.m_ScreenX = 0.30f;
  28. composer.m_ScreenY = 0.35f;
  29.  
  30. // Create a FreeLook vcam on object "Cylinder"
  31. freelook = new GameObject("FreeLook").AddComponent<CinemachineFreeLook>();
  32. freelook.m_LookAt = GameObject.Find("Cylinder/Sphere").transform;
  33. freelook.m_Follow = GameObject.Find("Cylinder").transform;
  34. freelook.m_Priority = 11;
  35.  
  36. // You can access the individual rigs in the freeLook if you want.
  37. // FreeLook rigs come with Composers pre-installed.
  38. // Note: Body MUST be Orbital Transposer. Don't change it.
  39. CinemachineVirtualCamera topRig = freelook.GetRig(0);
  40. CinemachineVirtualCamera middleRig = freelook.GetRig(1);
  41. CinemachineVirtualCamera bottomRig = freelook.GetRig(2);
  42. topRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = 0.35f;
  43. middleRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = 0.25f;
  44. bottomRig.GetCinemachineComponent<CinemachineComposer>().m_ScreenY = 0.15f;
  45. }
  46.  
  47. float lastSwapTime = 0;
  48. void Update()
  49. {
  50. // Switch cameras from time to time to show blending
  51. if (Time.realtimeSinceStartup - lastSwapTime > 5)
  52. {
  53. freelook.enabled = !freelook.enabled;
  54. lastSwapTime = Time.realtimeSinceStartup;
  55. }
  56. }
  57. }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement