Enter full screen on Computer without a new scene
Hi, I'm trying to make a computer that your able to click on and go full screen in, but you can click back out of to go back to the room, but also be able to click back in it, if anyone can help and actually success and test their script, It'd be greatly amazing! Thank you!
C# or just Java~
Answer by TBruce · Jun 15, 2016 at 10:47 PM
This will do the trick
using UnityEngine;
using System.Collections;
public class ToggleObjectScale : MonoBehaviour
{
private bool objectMaximised = false;
private Vector3 norlmalScale = Vector3.zero;
private Vector3 maxScale = Vector3.zero;
void Start()
{
norlmalScale = gameObject.transform.localScale;
maxScale = new Vector3(Screen.width / norlmalScale.x, Screen.height / norlmalScale.y, norlmalScale.z);
}
void OnMouseDown()
{
if (objectMaximised)
{
gameObject.transform.localScale = norlmalScale;
}
else
{
gameObject.transform.localScale = maxScale;
}
objectMaximised = !objectMaximised;
}
}
You need to make sure that there is a collider on the GameObject.
The thing is it will max the complete object. You may want to create an object that just represents the screen and attach this script to it. That way it will only enlarge the screen itself.
I did a quick test using a Quad and a sample material. Worked fine.
This is another version which is a little better
using UnityEngine;
using System.Collections;
public class ToggleObjectScale : MonoBehaviour
{
private bool objectMaximised = false;
private Vector3 norlmalScale = Vector3.zero;
public Vector3 maxScale = Vector3.zero;
public float distance = -10;
public float goDepth = 0.3f;
private Vector3 v3ViewPort = Vector3.zero;
private Vector3 v3BottomLeft = Vector3.zero;
private Vector3 v3TopRight = Vector3.zero;
void Start ()
{
norlmalScale = gameObject.transform.localScale;
goDepth = Camera.main.nearClipPlane;
distance = Camera.main.transform.position.z;
v3ViewPort.Set(0, 0, distance);
v3BottomLeft = Camera.main.ViewportToWorldPoint(v3ViewPort);
v3ViewPort.Set(1, 1, distance);
v3TopRight = Camera.main.ViewportToWorldPoint(v3ViewPort);
maxScale = new Vector3(v3BottomLeft.x - v3TopRight.x, v3BottomLeft.y - v3TopRight.y, goDepth);
}
void OnMouseDown()
{
if (objectMaximised)
{
gameObject.transform.localScale = norlmalScale;
}
else
{
gameObject.transform.localScale = maxScale;
}
objectMaximised = !objectMaximised;
}
}
i
Ah what to do here? The script seems to have no errors, and i placed it on a JavaScript and C#.
Nothing pops out on this, thanks!
This is one of your scripts navigateenemy.
You need to make sure that the name of the class and the file match exactly (this includes case).
In other words, in the case of my example above, the name of my file is
ToggleObjectScale.cs
which matches the class name exactly.
That is awesome! It does work, amaze~! Is there a way where if i click on it, it'll go to a different camera, and it'll be a click and point?
Basically, the screen just enlarges and my character can still look around and not be on the screen. Thanks~!
Follow this Question
Related Questions
How To Show a Question UI Canvas After Collider ? 1 Answer
not run app again when read nfc tag 0 Answers
Help, Losing lives too easily 1 Answer
Unity Package Manager Error 0 Answers
AI walk around and flashlight stop 1 Answer