2016-12-28 1 views
-3

좋아요 그래서 나는이 카메라는 유니티 내 계층에 설정 한 : 게임 내, 내가 어떻게 두 카메라 사이를 전환 할 때 내가 알고 싶습니다 특정 키를 누르면 카메라를 간단히 전환 할 수 있습니까?

enter image description here

가 특정 키를 눌렀을 때 ? 나는 아마 이것을위한 스크립트를 만들 필요가있을 거라는 것을 알고 있는데, 어떻게 해야할지 모르겠다.

+0

을 추가 할 수 있습니다 : 업데이트 방법에 넣고 http://answers.unity3d.com/questions/63221/how- to-set-main-camera.html – Keiwan

+1

누군가가 당신을 위해 스크립트를 작성하기를 기다리기만하면 배우지 않을 것입니다. 당신은 뭔가가 있어야합니다. 적어도 간단한 if 문을 키보드에서 읽은 다음 기본 코드를 변경하는 간단한 코드 행을 읽습니다. 그냥 구글 "화합 변경 메인 카메라" – Programmer

답변

1

당신이 도울 수있는 여러 대의 카메라

using UnityEngine; 

using System.Collections; 

public class CameraController : MonoBehaviour { 

// Use this for initialization 
public Camera[] cameras; 
private int currentCameraIndex; 

// Use this for initialization 
void Start() { 
    currentCameraIndex = 0; 

    //Turn all cameras off, except the first default one 
    for (int i=1; i<cameras.Length; i++) 
    { 
     cameras[i].gameObject.SetActive(false); 
    } 

    //If any cameras were added to the controller, enable the first one 
    if (cameras.Length>0) 
    { 
     cameras [0].gameObject.SetActive (true); 
     Debug.Log ("Camera with name: " + cameras [0].GetComponent<Camera>().name + ", is now enabled"); 
    } 
} 

// Update is called once per frame 
void Update() { 
    //If the c button is pressed, switch to the next camera 
    //Set the camera at the current index to inactive, and set the next one in the array to active 
    //When we reach the end of the camera array, move back to the beginning or the array. 


} 

public void Change() 
{ 
     currentCameraIndex ++; 
     Debug.Log ("C button has been pressed. Switching to the next camera"); 
     if (currentCameraIndex < cameras.Length) 
     { 
      cameras[currentCameraIndex-1].gameObject.SetActive(false); 
      cameras[currentCameraIndex].gameObject.SetActive(true); 
      Debug.Log ("Camera with name: " + cameras [currentCameraIndex].GetComponent<Camera>().name + ", is now enabled"); 
     } 
     else 
     { 
      cameras[currentCameraIndex-1].gameObject.SetActive(false); 
      currentCameraIndex = 0; 
      cameras[currentCameraIndex].gameObject.SetActive(true); 
      Debug.Log ("Camera with name: " + cameras [currentCameraIndex].GetComponent<Camera>().name + ", is now enabled"); 
     } 
    } 

}

1

매우 기본적인 질문이므로 C# 튜토리얼을 참조하십시오.

어쨌든 이것은 가능합니다.

if (Input.GetKeyDown("space")) 
    { 
     //don't forget to set one as active either in the Start() method 
     //or deactivate 1 camera in the Editor before playing 
     if (Camera1.active == true) 
     { 
      Camera1.SetActive(false); 
      Camera2.SetActive(true); 
     } 

     else 
     { 
      Camera1.SetActive(true); 
      Camera2.SetActive(false); 
     } 
    } 
관련 문제