I am trying to make a control room system, in which there are 5 monitors, with 1 main monitor and 4 side monitors, and I want to be able to click on the side monitors and they appear on the large main monitor. I attempted to do this by moving just the canvases, but the scale keeps distorting, and lossyScale.Set(); doesn’t seem to change it. Any ideas would be appreciated, do you think moving the canvas is the best way to go or perhaps I should take a different approach?
My code:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class ScreenSwap : MonoBehaviour {
public List<GameObject> screens = new List<GameObject>();
Transform mainScreenHolder;
GameObject currentMainScreen;
Vector3[] screenPositions = new Vector3[5];
Quaternion[] screenRotations = new Quaternion[5];
// Use this for initialization
void Start () {
currentMainScreen = screens[0];
mainScreenHolder = currentMainScreen.transform.parent;
for(int i = 0; i< 5; i++)
{
screenRotations _= screens*.transform.localRotation;*_
screenPositions = screens*.transform.localPosition;*
* }*
* }*
* // Update is called once per frame*
* void Update () {*
* if(Input.GetMouseButtonDown(0))*
* {*
* Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);*
* RaycastHit hit;*
* if(Physics.Raycast(ray,out hit))*
* {*
* if(hit.collider.gameObject.tag == “SideScreen”)*
* {*
* GameObject screen = hit.collider.transform.GetChild(0).gameObject;*
* SwapScreen(screen, screens.IndexOf(screen));*
* }*
* }*
* }*
* }*
* void SwapScreen(GameObject sideScreen, int screenIndex)*
* {*
* RectTransform mainScreenCanvas = currentMainScreen.GetComponent();*
* RectTransform sideScreenCanvas = sideScreen.GetComponent();*
* currentMainScreen.transform.SetParent(sideScreen.transform.parent);*
* sideScreen.transform.SetParent(mainScreenHolder);*
* currentMainScreen.transform.localPosition = screenPositions[screenIndex];*
* currentMainScreen.transform.localRotation = screenRotations[screenIndex];*
* //mainScreenCanvas.lossyScale = new Vector3(0.001f,0.001f,0.001f);*
* mainScreenCanvas.lossyScale.Set(0.001f,0.001f,0.001f);*
* mainScreenCanvas.sizeDelta = new Vector2(950f,950f);*
* mainScreenCanvas.lossyScale.Set(0.001f,0.001f,0.001f);*
* sideScreen.transform.localPosition = screenPositions[0];*
* sideScreen.transform.localRotation = screenRotations[0];*
* //sideScreenCanvas.lossyScale = new Vector3(0.001f,0.001f,0.001f);*
* sideScreenCanvas.lossyScale.Set(0.001f,0.001f,0.001f);*
* sideScreenCanvas.sizeDelta = new Vector2(950f,950f);*
* sideScreenCanvas.lossyScale.Set(0.001f,0.001f,0.001f);*
* sideScreen.tag = “MainScreen”;*
* currentMainScreen.tag = “SideScreen”;*
* currentMainScreen = sideScreen;*
* }*
}
Some screenshots:
[51845-screenie1.png|51845]
[51846-screenie2.png*|51846]*
*
*