fixed item system
This commit is contained in:
@ -2,7 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DoorInteractable : InteractableItem
|
||||
public class DoorInteractable : HeavyItemReceiver
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform powerCoreCenter;
|
||||
@ -91,6 +91,8 @@ public class DoorInteractable : InteractableItem
|
||||
else if(insertedCore!=null&&heavyInvent==null)
|
||||
{
|
||||
heavyInvent = insertedCore;
|
||||
print("Picked up:" + heavyInvent.name);
|
||||
insertedCore = null;
|
||||
//get ref of player perhaps
|
||||
return true;
|
||||
}
|
||||
|
13
Assets/Scripts/Item/HeavyItemReceiver.cs
Normal file
13
Assets/Scripts/Item/HeavyItemReceiver.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class HeavyItemReceiver : InteractableItem
|
||||
{
|
||||
protected HeavyInteractableItem item;
|
||||
[SerializeField]
|
||||
[Tooltip("Specify the keyword search in the name of the item!")]
|
||||
protected string searchString;
|
||||
|
||||
|
||||
}
|
11
Assets/Scripts/Item/HeavyItemReceiver.cs.meta
Normal file
11
Assets/Scripts/Item/HeavyItemReceiver.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aef7fff75652a9a499e312b65c8f91b1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -43,7 +43,6 @@ public class PistolComponent : MonoBehaviour
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 50))
|
||||
{
|
||||
print(hit.transform.name);
|
||||
targetObject.gameObject.transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,21 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
flashlightEnabled = this.flashlight.gameObject.activeSelf;
|
||||
}
|
||||
|
||||
private bool receiverInRange(out int index)
|
||||
{
|
||||
int i = 0;
|
||||
foreach(InteractableItem item in this.itemsInRange)
|
||||
{
|
||||
if(item is HeavyItemReceiver)
|
||||
{
|
||||
index = i;
|
||||
return true;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
index = -1;
|
||||
return false;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
@ -87,6 +102,8 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
else if (heavyItemsInRange.Count > 0)
|
||||
{
|
||||
pickupFound = true;
|
||||
|
||||
|
||||
heavyInvent = heavyItemsInRange[0];
|
||||
|
||||
heavyInvent.transform.parent = carryingPos;
|
||||
@ -95,6 +112,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
heavyItemsInRange.Remove(heavyItemsInRange[0]);
|
||||
heavyInvent.Disable();
|
||||
heavyInvent.DisableAll();
|
||||
|
||||
}
|
||||
if (!pickupFound)
|
||||
{
|
||||
@ -105,6 +123,20 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
if (!item.Interact(ref invent, ref heavyInvent))
|
||||
{
|
||||
item.Interact();
|
||||
}else if(item is HeavyItemReceiver)
|
||||
{
|
||||
if(heavyInvent != null)
|
||||
{
|
||||
heavyInvent.transform.parent = carryingPos;
|
||||
heavyInvent.transform.localPosition = Vector3.zero;
|
||||
heavyInvent.transform.localEulerAngles = Vector3.zero;
|
||||
heavyItemsInRange.Remove(heavyInvent);
|
||||
heavyInvent.GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
|
||||
heavyInvent.Disable();
|
||||
heavyInvent.DisableAll();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -113,10 +145,21 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
heavyInvent.transform.parent = null;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = false;
|
||||
heavyInvent.EnableAll();
|
||||
heavyInvent = null;
|
||||
int refIndex;
|
||||
if (itemsInRange.Count > 0&&receiverInRange(out refIndex)) {
|
||||
((HeavyItemReceiver)itemsInRange[refIndex]).Interact(ref this.invent, ref heavyInvent);
|
||||
heavyInvent = null;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
heavyInvent.transform.parent = null;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = false;
|
||||
heavyInvent.EnableAll();
|
||||
heavyInvent = null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -126,7 +169,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
if (Input.GetButtonDown("Fire2"))
|
||||
{
|
||||
print(this.GunEnabled);
|
||||
//print(this.GunEnabled);
|
||||
if (!this.GunEnabled)
|
||||
{
|
||||
|
||||
@ -170,7 +213,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
public void EnableFlashlight()
|
||||
{
|
||||
print("Enabling Flashlight...");
|
||||
|
||||
flashlight.gameObject.SetActive(true);
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
|
||||
selMaterial.SetColor("_EmissionColor", new Color(255, 255, 255, 255));
|
||||
@ -179,7 +222,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
public void DisableFlashlight()
|
||||
{
|
||||
print("Disabling Flashlight...");
|
||||
|
||||
flashlight.gameObject.SetActive(false);
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", new Color(0, 0, 0));
|
||||
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
|
||||
@ -188,7 +231,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.gameObject.GetComponent<InteractableItem>() != null)
|
||||
|
Reference in New Issue
Block a user