using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class appear1 : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Update();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("2"))
{
disappear();
}
if (Input.GetKeyDown("1"))
{
Appear();
}
}
void Appear()
{
gameObject.SetActive(true);
}
void disappear()
{
gameObject.SetActive(false);
}
}
There is no need to call Update on Start since Update is called every frame. Try doing this.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class appear1 : MonoBehaviour
{
public Camera cam;
// Start is called before the first frame update
void Start()
{
cam.enabled=true; //assuming that camera is active on scene load
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(“2”))
{
disappear();
}
if (Input.GetKeyDown(“1”))
{
Appear();
}
}
void Appear()
{
cam.enabled=true;
}
void disappear()
{
cam.enabled=false;
}
}