updates to scene. Working on pickup
This commit is contained in:
102
Assets/Scripts/Item/DoorInteractable.cs
Normal file
102
Assets/Scripts/Item/DoorInteractable.cs
Normal file
@ -0,0 +1,102 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DoorInteractable : InteractableItem
|
||||
{
|
||||
[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;
|
||||
//get ref of player perhaps
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Item/DoorInteractable.cs.meta
Normal file
11
Assets/Scripts/Item/DoorInteractable.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f575b137603a4b4282a6551120c979a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -4,10 +4,11 @@ using UnityEngine;
|
||||
|
||||
public class HeavyInteractableItem : InteractableItem
|
||||
{
|
||||
private Vector3 init_rot;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
init_rot = transform.eulerAngles;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@ -18,10 +19,24 @@ public class HeavyInteractableItem : InteractableItem
|
||||
public void DisableAll()
|
||||
{
|
||||
this.GetComponent<Collider>().enabled = false;
|
||||
|
||||
}
|
||||
public override bool Interact()
|
||||
{
|
||||
//Todo
|
||||
return false;
|
||||
}
|
||||
public override bool Interact(ref Inventory inventory,ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void EnableAll()
|
||||
{
|
||||
this.GetComponent<Collider>().enabled = true;
|
||||
this.transform.eulerAngles = new Vector3(init_rot.x,transform.eulerAngles.y,init_rot.z);
|
||||
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
|
@ -7,7 +7,7 @@ using UnityEngine.UI;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class InteractableItem : CarryableItem
|
||||
public abstract class InteractableItem : CarryableItem
|
||||
{
|
||||
|
||||
|
||||
@ -38,10 +38,9 @@ public class InteractableItem : CarryableItem
|
||||
target_alpha = 0;
|
||||
isEnabled = true;
|
||||
}
|
||||
public void Interact()
|
||||
{
|
||||
|
||||
}
|
||||
public abstract bool Interact();
|
||||
public abstract bool Interact(ref Inventory inventory,ref HeavyInteractableItem heavyInvent);
|
||||
|
||||
protected void BaseAwake()
|
||||
{
|
||||
interaction_texts = interactionCanvas.GetComponentsInChildren<TMP_Text>();
|
||||
|
@ -17,4 +17,13 @@ public class KeyItem : InteractableItem
|
||||
{
|
||||
|
||||
}
|
||||
public override bool Interact()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
public override bool Interact(ref Inventory inventory,ref HeavyInteractableItem heavyInvent)
|
||||
{
|
||||
return this.Interact();
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user