50 lines
1.0 KiB
C#
50 lines
1.0 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>();
|
|
|
|
// 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))
|
|
{
|
|
GetComponent<SpriteRenderer>().sprite = sprites[0];
|
|
}
|
|
}
|
|
}
|
|
}
|