Question by
YCFENG · Dec 11, 2016 at 08:56 AM ·
onguieditor scripting
How to get OnGUI button work in Editor Mode
I have used OnGUI button to change the camera (First Player View / Third Player View) in Game View when I click on the button. The program works well in Play Mode. However, when I added the attribute [ExecuteInEditMode] to the program and tried to click the button in Editor Mode, the Game View remained unchanged. How could I get my OnGUI button work in Editor Mode?
using UnityEngine;
using UnityEditor;
using System.Collections;
[ExecuteInEditMode]
public class ViewChange : MonoBehaviour {
public GameObject firstPlayerCamera;
public GameObject thirdPlayerCamera;
void OnGUI(){
if (GUI.Button (new Rect (10, 10, 150, 50), "View Change")) {
float temp = firstPlayerCamera.camera.depth;
firstPlayerCamera.camera.depth = thirdPlayerCamera.camera.depth;
thirdPlayerCamera.camera.depth = temp;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How to render object under everything else? 0 Answers
Editor tool for selecting inverse dependencies, no-longer works in Unity 5.4? 1 Answer
Auto resize/rescale ongui 0 Answers
Editor slider like "Quality Settings cascade split" 1 Answer
Warning:Trying to move asset to location it came from...[Please Help] 0 Answers