so i created a model of a laptop and i want to make it when i press the key (E) on the laptop, change the scene to other scene.
Hi, laucem. I tried to get over it for a while and came out with creating a array and siwtching elements when āEā is pressed. It starts from zero and then increases per press and thwn it goes back to beginning. I wrote this code by using a sprite for the screen of the laptop.
using UnityEngine;
public class SceneChange : MonoBehaviour
{
public GameObject Scene;
public Sprite[] Sprites;
public Sprite CurrentSprite;
public int index;
// Start is called before the first frame update
void Awake()
{
Scene.GetComponent<SpriteRenderer>().sprite = CurrentSprite;
CurrentSprite = Sprites[0];
}
// Update is called once per frame
void Update()
{
CurrentSprite = Sprites[index];
Scene.GetComponent<SpriteRenderer>().sprite = CurrentSprite;
if (Input.GetKeyDown(KeyCode.E))
{
if (index < Sprites.Length)
{
index++;
}
if (index == Sprites.Length)
{
index = 0;
}
}
}
}
I hope tihs helps and you have any questions feel free to ask about it.