updates to scene. Working on pickup
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
@ -10,6 +11,8 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private List<InteractableItem> itemsInRange= new List<InteractableItem>();
|
||||
private List<HeavyInteractableItem> heavyItemsInRange = new List<HeavyInteractableItem>();
|
||||
private Inventory invent;
|
||||
public Inventory Inventory { get { return invent; } }
|
||||
public static PlayerInteractionHandler instance;
|
||||
[SerializeField]
|
||||
private Light flashlight;
|
||||
[SerializeField]
|
||||
@ -23,10 +26,12 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
public bool IsCarrying { get { return heavyInvent !=null; } }
|
||||
[SerializeField]
|
||||
private Transform carryingPos;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
invent = this.transform.parent.GetComponent<Inventory>();
|
||||
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
|
||||
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
|
||||
@ -39,26 +44,62 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
//
|
||||
if(Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
if(itemsInRange.Count > 0)
|
||||
{
|
||||
invent.AddItem(itemsInRange[0]);
|
||||
itemsInRange[0].transform.gameObject.SetActive(false);
|
||||
itemsInRange.Remove(itemsInRange[0]);
|
||||
}
|
||||
else if(heavyItemsInRange.Count > 0)
|
||||
if (!IsCarrying)
|
||||
{
|
||||
int t_index = 0;
|
||||
bool pickupFound = false;
|
||||
if (itemsInRange.Count > 0)
|
||||
{
|
||||
while (t_index<itemsInRange.Count&&!itemsInRange[t_index].CanPickup)
|
||||
{
|
||||
t_index++;
|
||||
}
|
||||
if (t_index != itemsInRange.Count)
|
||||
{
|
||||
pickupFound = true;
|
||||
invent.AddItem(itemsInRange[t_index]);
|
||||
itemsInRange[0].transform.gameObject.SetActive(false);
|
||||
itemsInRange.Remove(itemsInRange[t_index]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if (heavyItemsInRange.Count > 0)
|
||||
{
|
||||
pickupFound = true;
|
||||
heavyInvent = heavyItemsInRange[0];
|
||||
|
||||
heavyInvent= heavyItemsInRange[0];
|
||||
heavyInvent.transform.parent = carryingPos;
|
||||
heavyInvent.transform.localPosition = Vector3.zero;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
|
||||
heavyItemsInRange.Remove(heavyItemsInRange[0]);
|
||||
heavyInvent.Disable();
|
||||
heavyInvent.DisableAll();
|
||||
}
|
||||
if (!pickupFound)
|
||||
{
|
||||
foreach(InteractableItem item in itemsInRange)
|
||||
{
|
||||
if (!item.CanPickup)
|
||||
{
|
||||
if(!item.Interact(ref invent, ref heavyInvent))
|
||||
{
|
||||
item.Interact();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
heavyInvent.transform.parent = null;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = false;
|
||||
heavyInvent.EnableAll();
|
||||
heavyInvent = null;
|
||||
|
||||
heavyInvent.transform.parent = carryingPos;
|
||||
heavyInvent.transform.localPosition = Vector3.zero;
|
||||
heavyInvent.GetComponent<Rigidbody>().isKinematic = true;
|
||||
heavyItemsInRange.Remove(heavyItemsInRange[0]);
|
||||
heavyInvent.Disable();
|
||||
heavyInvent.DisableAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (Input.GetButtonDown("Fire2"))
|
||||
{
|
||||
@ -66,7 +107,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
if (flashlight.gameObject.activeSelf)
|
||||
{
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
|
||||
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
|
||||
selMaterial.SetColor("_EmissionColor", new Color(255,255, 255, 255));
|
||||
flashlight3D.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
|
@ -42,6 +42,7 @@ public class PlayerMovementController : MonoBehaviour
|
||||
movement += transform.forward * Mathf.Abs(y) * Time.deltaTime * speed;//+(transform.right*x*Time.deltaTime*speed);
|
||||
//movement += transform.right * Mathf.Abs(x) * Time.deltaTime * sideSpeed;
|
||||
movement += transform.forward * Mathf.Abs(x) * Time.deltaTime * speed;
|
||||
movement += Vector3.down * 9.8f;
|
||||
ccontroller.Move(movement);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user