Hi! Fairly new to C# but I know a fair amount.
The problem I have is assigning a key (in this case: x) to make it switch the Minimap camara on and off.
I think the way I’ve coded it, its just running the on and off state’s at the same time resulting in no change.
How can I fix what seems like a really easy thing to get working?
Cheers!
using UnityEngine;
using System.Collections;
public class MiniMapState : MonoBehaviour {
Transform myTransform;
public int mapState;
// Use this for initialization
void Start () {
myTransform = transform;
mapState = 1;
}
// Update is called once per frame
void Update () {
if(mapState == 1)
{
if(Input.GetKeyDown("x"))
{
GameObject.Find("Minimap").GetComponent<Camera>().enabled = false;
}
if(Input.GetKeyUp("x"))
{
mapState = 0;
}
}
if(mapState == 0);
{
if(Input.GetKeyDown("x"))
{
GameObject.Find("Minimap").GetComponent<Camera>().enabled = true;
}
if(Input.GetKeyUp("x"))
{
mapState = 1;
}
}
}
}
Thanks! Had no idea about bool. Just for future understanding; what is this: toggleMe=!toggleMe? Does having =! simply change the state of the boolean to its opposite? True - False or False - True?
– PlumcakeI've posted an answer. A lot people seem to think that Unity is a managed application, but it's not. Unity is mainly written in C++ and Unity does it's own memory management of the native resources. On top of that you have Mono as scripting environment. Mono has it's own heap / heap area within the native application.
– Bunny83