1
0
Fork 0
This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
Global-Game-Jam-2019/Assets/Scripts/PickableObject.cs
2019-01-27 14:54:55 +01:00

45 lines
1.2 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PickableObject : MonoBehaviour
{
private PlayerScript playerTriggered;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (playerTriggered is PlayerScript)
{
if (Input.GetKeyDown(KeyCode.E) || Manette.IsUse())
{
if (playerTriggered.PickupObject(new CombustibleItem(Random.Range(0,10), GetComponent<SpriteRenderer>().sprite))) Destroy(this.gameObject);
playerTriggered = null;
}
}
}
void OnTriggerEnter2D(Collider2D c)
{
if (c.gameObject.tag.Equals("Player"))
{
playerTriggered = c.gameObject.GetComponent<PlayerScript>();
playerTriggered.SetInteractMessage(true, this.gameObject.tag);
}
}
void OnTriggerExit2D(Collider2D c)
{
if (c.gameObject.tag.Equals("Player"))
{
playerTriggered = null;
c.gameObject.GetComponent<PlayerScript>().SetInteractMessage(false, this.gameObject.tag);
}
}
}