25 lines
775 B
C#
25 lines
775 B
C#
using UnityEngine;
|
|
/// <summary>
|
|
/// Handles what happens when the user clicks on a collider
|
|
/// </summary>
|
|
public class ClickBehavior : MonoBehaviour
|
|
{
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
Vector2 clickPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
|
//RaycastHit2D hit = Physics2D.Raycast(clickPoint, transform.up);
|
|
Collider2D collider = Physics2D.OverlapPoint(clickPoint);
|
|
if (collider != null)
|
|
{
|
|
Debug.Log("Colliding with " + collider.tag);
|
|
if (collider.CompareTag("Resource"))
|
|
{
|
|
collider.GetComponent<ResourceMaker>().GenerateResource();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|