fixed item system
This commit is contained in:
@ -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