gun elements added and uvs updated to better space out texture.
This commit is contained in:
@ -53,6 +53,7 @@ public class PlayerAnimationController : MonoBehaviour
|
||||
void Update()
|
||||
{
|
||||
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
||||
animController.SetBool("HasGun",interactionHandler.GunEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Xml;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
@ -17,6 +18,7 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
private Light flashlight;
|
||||
[SerializeField]
|
||||
private GameObject flashlight3D;
|
||||
private bool flashlightEnabled = true;
|
||||
[SerializeField]
|
||||
private int materialIndex = 1;
|
||||
private Material selMaterial;
|
||||
@ -24,8 +26,16 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
|
||||
private HeavyInteractableItem heavyInvent;
|
||||
public bool IsCarrying { get { return heavyInvent !=null; } }
|
||||
public bool GunEnabled { get { return this.gunEnabled; } }
|
||||
private bool gunEnabled = false;
|
||||
[SerializeField]
|
||||
private Transform carryingPos;
|
||||
|
||||
private ItemSelector itemSelector;
|
||||
[SerializeField]
|
||||
private bool useItemSelector = true;
|
||||
[SerializeField]
|
||||
private PistolComponent pistol;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
@ -35,13 +45,44 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
invent = this.transform.parent.GetComponent<Inventory>();
|
||||
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
|
||||
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
|
||||
|
||||
itemSelector = ItemSelector.instance;
|
||||
pistol.gameObject.SetActive(this.gunEnabled);
|
||||
flashlightEnabled = this.flashlight.gameObject.activeSelf;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//
|
||||
if (itemSelector == null)
|
||||
{
|
||||
itemSelector = ItemSelector.instance;
|
||||
}
|
||||
|
||||
if (useItemSelector)
|
||||
{
|
||||
|
||||
InteractableItem item = this.itemSelector.Selected;
|
||||
if(item != null)
|
||||
{
|
||||
if (item is HeavyInteractableItem)
|
||||
{
|
||||
heavyItemsInRange = new List<HeavyInteractableItem>() { (HeavyInteractableItem)item };
|
||||
itemsInRange = new List<InteractableItem> { item };
|
||||
print("Item:" + item.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsInRange = new List<InteractableItem> { item };
|
||||
heavyItemsInRange = new List<HeavyInteractableItem>();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
itemsInRange = new List<InteractableItem>();
|
||||
heavyItemsInRange = new List<HeavyInteractableItem>();
|
||||
}
|
||||
|
||||
}
|
||||
if(Input.GetButtonDown("Fire1"))
|
||||
{
|
||||
if (!IsCarrying)
|
||||
@ -103,22 +144,68 @@ public class PlayerInteractionHandler : MonoBehaviour
|
||||
}
|
||||
if (Input.GetButtonDown("Fire2"))
|
||||
{
|
||||
flashlight.gameObject.SetActive(!flashlight.gameObject.activeSelf);
|
||||
if (flashlight.gameObject.activeSelf)
|
||||
print(this.GunEnabled);
|
||||
if (!this.GunEnabled)
|
||||
{
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
|
||||
selMaterial.SetColor("_EmissionColor", new Color(255,255, 255, 255));
|
||||
flashlight3D.gameObject.SetActive(true);
|
||||
|
||||
if (!flashlight.gameObject.activeSelf)
|
||||
{
|
||||
EnableFlashlight();
|
||||
}
|
||||
else
|
||||
{
|
||||
DisableFlashlight();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", new Color(0, 0, 0));
|
||||
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
|
||||
flashlight3D.gameObject.SetActive(false);
|
||||
this.pistol.LightToggle();
|
||||
}
|
||||
|
||||
}
|
||||
if (Input.GetButtonDown("Fire3"))
|
||||
{
|
||||
if (!this.IsCarrying)
|
||||
{
|
||||
this.gunEnabled = !this.gunEnabled;
|
||||
if(!this.gunEnabled)
|
||||
pistol.Disable();
|
||||
pistol.gameObject.SetActive(this.gunEnabled);
|
||||
if (this.gunEnabled)
|
||||
pistol.Enable();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if (this.GunEnabled)
|
||||
{
|
||||
this.DisableFlashlight();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
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));
|
||||
flashlight3D.gameObject.SetActive(true);
|
||||
this.flashlightEnabled = true;
|
||||
}
|
||||
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));
|
||||
flashlight3D.gameObject.SetActive(false);
|
||||
this.flashlightEnabled = false;
|
||||
}
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.gameObject.GetComponent<InteractableItem>() != null)
|
||||
|
Reference in New Issue
Block a user