2023-03-21 19:49:47 +01:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
2023-04-04 05:00:18 +02:00
|
|
|
public class DoorInteractable : HeavyItemReceiver
|
2023-03-21 19:49:47 +01:00
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private Transform powerCoreCenter;
|
|
|
|
private HeavyInteractableItem insertedCore;
|
|
|
|
private Vector3 priorLocalPos;
|
|
|
|
private Vector3 priorLocalRot;
|
|
|
|
private Vector3 priorScale;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float minAttractDist = 5;
|
|
|
|
[SerializeField]
|
|
|
|
private string nameSearched = "Power Core";
|
|
|
|
|
|
|
|
public bool Powered { get { return this.insertedCore!= null; } }
|
|
|
|
[SerializeField]
|
|
|
|
private Animator anim;
|
|
|
|
// Start is called before the first frame update
|
|
|
|
void Start()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
anim.SetBool("IsPowered", Powered);
|
|
|
|
}
|
|
|
|
public override bool Interact()
|
|
|
|
{
|
|
|
|
//print("INTERACTED!");
|
|
|
|
if(this.insertedCore== null)
|
|
|
|
{
|
|
|
|
HeavyInteractableItem[] worldHeavyItems = GameObject.FindObjectsOfType<HeavyInteractableItem>();
|
|
|
|
//print("Found:" + worldHeavyItems.Length);
|
|
|
|
for(int i = 0; i < worldHeavyItems.Length; i++)
|
|
|
|
{
|
|
|
|
HeavyInteractableItem item = worldHeavyItems[i];
|
|
|
|
|
|
|
|
if (!item.ItemName.Contains(nameSearched))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
float dist = Vector3.Distance(item.transform.position, powerCoreCenter.transform.position);
|
|
|
|
//print("DIST:" + dist);
|
|
|
|
if (dist <= minAttractDist)
|
|
|
|
{
|
|
|
|
Inventory _i = PlayerInteractionHandler.instance.Inventory;
|
|
|
|
this.Interact(ref _i, ref item);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
public override bool Interact(ref Inventory inventory,ref HeavyInteractableItem heavyInvent)
|
|
|
|
{
|
|
|
|
//print("INTERACTED 2");
|
|
|
|
// print(heavyInvent);
|
|
|
|
|
|
|
|
if (heavyInvent!=null&&heavyInvent.ItemName.Contains(nameSearched))
|
|
|
|
{
|
|
|
|
//print("DOOR OPEN!");
|
|
|
|
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
|
|
|
|
|
|
|
|
heavyInvent.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeAll;
|
|
|
|
priorLocalPos = heavyInvent.transform.localPosition;
|
|
|
|
priorLocalRot = heavyInvent.transform.localEulerAngles;
|
|
|
|
priorScale = heavyInvent.transform.localScale;
|
|
|
|
|
|
|
|
heavyInvent.transform.parent = powerCoreCenter;
|
|
|
|
|
|
|
|
heavyInvent.gameObject.transform.localPosition = Vector3.zero;
|
|
|
|
heavyInvent.gameObject.transform.localEulerAngles = Vector3.zero;
|
|
|
|
heavyInvent.transform.parent = null;
|
|
|
|
heavyInvent.gameObject.transform.localScale = priorScale;
|
|
|
|
|
|
|
|
insertedCore = heavyInvent;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if(insertedCore!=null&&heavyInvent==null)
|
|
|
|
{
|
|
|
|
heavyInvent = insertedCore;
|
2023-04-04 05:22:37 +02:00
|
|
|
|
2023-04-04 05:00:18 +02:00
|
|
|
insertedCore = null;
|
2023-03-21 19:49:47 +01:00
|
|
|
//get ref of player perhaps
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|