Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. {
  2.     public class SE_Camera_Menu : MonoBehaviour
  3.     {
  4.         [MenuItem("SamuelEinheri/Cameras/Top Down Camera")]
  5.         public static void CreateTopDownCamera()
  6.         {
  7.             GameObject[] selectedGameObject = Selection.gameObjects;
  8.  
  9.             if(selectedGameObject.Length > 0 && selectedGameObject[0].GetComponent<Camera>())
  10.             {
  11.                 if (selectedGameObject.Length < 2)
  12.                 {
  13.                     AttachTopDownScript(selectedGameObject[0].gameObject, null);
  14.                 }
  15.                 else if(selectedGameObject.Length == 2)
  16.                 {
  17.                     AttachTopDownScript(selectedGameObject[0].gameObject, selectedGameObject[1].transform);
  18.                 }
  19.                 else if(selectedGameObject.Length == 3)
  20.                 {
  21.                     EditorUtility.DisplayDialog("Camera Tools", "You can only select 2 GameObjects in the Scene" +
  22.                         " for this to work and the first selection needs to be a Camera!", "OK");
  23.                 }
  24.             }
  25.             else
  26.             {
  27.                 EditorUtility.DisplayDialog("Camera Tools", "You need to select a GameObject in the Scene that has" +
  28.                     " a Camera component assigned to it!", "OK");
  29.             }
  30.  
  31.         }
  32.         static void AttachTopDownScript(GameObject aCamera, Transform aTarget)
  33.         {
  34.             // Assign Top down Script to the camera
  35.             SE_TopDown_Camera cameraScript = null;
  36.             if(aCamera)
  37.             {
  38.                 cameraScript = aCamera.AddComponent<SE_TopDown_Camera>();
  39.            
  40.  
  41.                 // Check to see if we have a Target and we have a script reference
  42.                 if(cameraScript && aTarget)
  43.                 {
  44.                     cameraScript.m_Target = aTarget;
  45.                 }
  46.  
  47.                 Selection.activeGameObject = aCamera;
  48.             }
  49.  
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement