58 lines
1.3 KiB
C#
58 lines
1.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class SwitchSprite : MonoBehaviour
|
|
{
|
|
public bool inRange = false;
|
|
public Sprite[] sprites;
|
|
private List<int> availableSprites = new List<int>();
|
|
public int current;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
availableSprites.Add(1);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
{
|
|
if (collision.tag == "Player")
|
|
{
|
|
inRange = true;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerStay2D(Collider2D collision)
|
|
{
|
|
if (collision.tag == "Player")
|
|
{
|
|
inRange = true;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit2D(Collider2D collision)
|
|
{
|
|
inRange = false;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
if (inRange == true)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.E) && current != 1)
|
|
{
|
|
GetComponent<SpriteRenderer>().sprite = sprites[0];
|
|
current = 1;
|
|
}
|
|
else if (Input.GetKeyDown(KeyCode.E) && current == 1)
|
|
{
|
|
GetComponent<SpriteRenderer>().sprite = sprites[1];
|
|
current = 0;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|