Skip to content
Permalink
ea751f179f
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
47 lines (40 sloc) 1.87 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenueResize : MonoBehaviour
{
//resize main menu elements as soon as scene is loaded
void Awake()
{
/* call update functoin in Awake (Update is when scene updates,
* and I am calling that when scene loads because only need to store
* dynamic resolution code in one function that way and also because
* game resolution automatically changes when I adjust device resolution
* (at frame update). */
Update();
}
//resize for every frame update
void Update()
{
//get first button and store it
GameObject button = GameObject.Find("ScanButton");
/* place button on left-centre of screen in terms of width
* and vertical centre in terms of height */
button.transform.position = new Vector3((Screen.width * 0.25f), (Screen.height * 0.5f));
//get recttransform of button so can resize it
var buttonSize = button.GetComponent<RectTransform>();
/* resize button to 40% of screen width horizontally and vertically
* note: using same value for x and y because I created button image to have
* size 400 wide and 400 high. */
buttonSize.sizeDelta = new Vector2(Screen.width * 0.4f, Screen.width * 0.4f);
//get second button now
button = GameObject.Find("ListButton");
/* same resizing and repositioning explained for first button
* (only difference is button is aligned right-centre instead of left centre) */
button.transform.position = new Vector3((Screen.width * 0.75f), (Screen.height * 0.5f));
buttonSize = button.GetComponent<RectTransform>();
buttonSize.sizeDelta = new Vector2(Screen.width * 0.4f, Screen.width * 0.4f);
}
}