So I made a code to activate and deactivate 2Game Objects. Im programing since a month and i have no Idea whats wrong with the code. Please Awnser me. The first Time i press it it works but the second time it doesnt't. And after that it still doesnt works and so on.
This is the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Mapswitcher : MonoBehaviour
{
public GameObject map1;
bool map1active;
public GameObject map2;
bool map2active;
// Start is called before the first frame update
void Awake()
{
map1active = true;
map1.SetActive(true);
map2active = false;
map2.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Mapswitch") && map2active == false && map1active == true)
{
map1.SetActive(false);
map2.SetActive(true);
}
else if (Input.GetButtonDown("Mapswitch") && map2active == true && map1active == false)
{
map1.SetActive(true);
map2.SetActive(false);
}
}
}