Camera Editor,Camera Editor
Hi. I'm trying to make a camera Editor that can assign the camera to the player and the player to the camera as a target by selecting them in menu and clicking on the create the new camera Button, but my code right now assigns the camera to the player a target and give the camera script to the player. I can't find out what I'm doing wrong, can someone please read my code to see what I'm doing wrong? btw I'm making the selection right on the menu. this is the code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor;
namespace Rook.Cameras { public class CameraMenu : MonoBehaviour { [MenuItem("Rook/Cameras/Top Down Camera")] public static void CreateTopDownCamera() { GameObject[] selectedGo = Selection.gameObjects;
if(selectedGo.Length > 0 || selectedGo[0].GetComponent<Camera>())
{
if(selectedGo.Length < 2)
{
AttachTopDownScript(selectedGo[0].gameObject, null);
}
else if(selectedGo.Length == 2)
{
AttachTopDownScript(selectedGo[0].gameObject, selectedGo[1].transform);
}
else if(selectedGo.Length == 3)
{
EditorUtility.DisplayDialog("Camera Tool", "You can only select two GameObjects in the scene for this to work and first selection needs to be a Camera!", "OK");
}
}
else
{
EditorUtility.DisplayDialog("Camera Tool", "Please Select a Gameobject in the scene that has a Camera component in it!", "OK");
}
}
static void AttachTopDownScript(GameObject aCamera, Transform aTarget)
{
TopDownCamera cameraScript = null;
if (aCamera)
{
cameraScript = aCamera.AddComponent<TopDownCamera>();
if(cameraScript || aTarget)
{
cameraScript.target = aTarget;
}
Selection.activeGameObject = aCamera;
}
}
}
}
Your answer
Follow this Question
Related Questions
there is no build fail but editor script doesn't work in build 1 Answer
How to make flashlight stay with camera? 0 Answers
Set Main Camera in Networkmanager 1 Answer
How to change a game objects tag after it has been randomly selected? 0 Answers
inspector button to capture a new selected object in scene or hierarchy view 0 Answers