You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.3 KiB
52 lines
1.3 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
|
|
public class Interactable : MonoBehaviour
|
|
{
|
|
[SerializeField] protected Collider _collider;
|
|
[SerializeField] protected Player user;
|
|
[SerializeField] protected List<Interaction> interactions;
|
|
|
|
public List<Interaction> Interactions => interactions;
|
|
public int ActiveInteractionsCount
|
|
{
|
|
get
|
|
{
|
|
int count = 0;
|
|
|
|
foreach (Interaction interaction in interactions)
|
|
{
|
|
if (interaction.Active) count++;
|
|
}
|
|
|
|
return count;
|
|
}
|
|
}
|
|
|
|
public void CreateInteractions()
|
|
{
|
|
int count = ActiveInteractionsCount;
|
|
Bounds obj = _collider.bounds;
|
|
|
|
float sizeobj = 1f;
|
|
float sizebtw = 0.2f;
|
|
|
|
float width = count * sizeobj + (count - 1) * sizebtw;
|
|
Vector3 point = new Vector3(obj.center.x - width / 2f + sizeobj / 2f, obj.center.y + obj.extents.y);
|
|
|
|
foreach (Interaction interaction in interactions)
|
|
{
|
|
if (!interaction.Active) continue;
|
|
|
|
interaction.InitializeButton(point);
|
|
point.x += sizeobj + sizebtw;
|
|
}
|
|
}
|
|
|
|
public void Destroy()
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
}
|
|
|