gun elements added and uvs updated to better space out texture.
This commit is contained in:
58
Assets/Scripts/Interactable/ItemSelector.cs
Normal file
58
Assets/Scripts/Interactable/ItemSelector.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ItemSelector : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Camera cam;
|
||||
private InteractableItem selected;
|
||||
[SerializeField]
|
||||
private bool debug = false;
|
||||
[SerializeField]
|
||||
private LayerMask mask;
|
||||
public static ItemSelector instance;
|
||||
[SerializeField]
|
||||
private float range = 1;
|
||||
|
||||
public InteractableItem Selected { get { return selected; } }
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
|
||||
RaycastHit hit;
|
||||
|
||||
if (Physics.Raycast(ray, out hit,range,layerMask:mask))
|
||||
{
|
||||
if(selected!= null||hit.transform.gameObject==null)
|
||||
{
|
||||
selected.Disable();
|
||||
}
|
||||
|
||||
selected = hit.transform.gameObject.GetComponent<InteractableItem>();
|
||||
selected.Enable();
|
||||
print(selected);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (selected != null)
|
||||
{
|
||||
selected.Disable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Interactable/ItemSelector.cs.meta
Normal file
11
Assets/Scripts/Interactable/ItemSelector.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9eb8c70704eba0741a0b281bc6ff3d8c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -25,7 +25,7 @@ public abstract class InteractableItem : CarryableItem
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
print("Enabled!");
|
||||
//print("Enabled!");
|
||||
interactionCanvas.transform.LookAt((GameObject.FindGameObjectWithTag("MainCamera").transform.position));
|
||||
interactionCanvas.transform.Rotate(0, 180, 0);
|
||||
target_alpha = 1;
|
||||
@ -34,7 +34,7 @@ public abstract class InteractableItem : CarryableItem
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
print("Disabled!");
|
||||
//print("Disabled!");
|
||||
target_alpha = 0;
|
||||
isEnabled = true;
|
||||
}
|
||||
|
8
Assets/Scripts/Pistol.meta
Normal file
8
Assets/Scripts/Pistol.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7cd9f53a6ff4b6443b3d5b95e50767e4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
68
Assets/Scripts/Pistol/PistolComponent.cs
Normal file
68
Assets/Scripts/Pistol/PistolComponent.cs
Normal file
@ -0,0 +1,68 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PistolComponent : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Light targetingLight;
|
||||
|
||||
private bool IsEnabled = false;
|
||||
|
||||
GameObject targetObject;
|
||||
[SerializeField]
|
||||
GameObject targetObjectPrefab;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (this.IsEnabled)
|
||||
{
|
||||
Ray ray = new Ray(transform.position, transform.up);
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(ray, out hit, 50))
|
||||
{
|
||||
print(hit.transform.name);
|
||||
targetObject.gameObject.transform.position = hit.point;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
public void Enable()
|
||||
{
|
||||
IsEnabled = true;
|
||||
if (targetObject == null)
|
||||
{
|
||||
targetObject = Instantiate(targetObjectPrefab);
|
||||
|
||||
}
|
||||
}
|
||||
public void Disable()
|
||||
{
|
||||
IsEnabled = false;
|
||||
if (targetObject != null)
|
||||
{
|
||||
Destroy(targetObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void LightToggle() {
|
||||
this.targetingLight.gameObject.SetActive(!this.targetingLight.gameObject.activeSelf);
|
||||
}
|
||||
public bool IsLightOn { get { return this.targetingLight.gameObject.activeSelf; } }
|
||||
|
||||
}
|
11
Assets/Scripts/Pistol/PistolComponent.cs.meta
Normal file
11
Assets/Scripts/Pistol/PistolComponent.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0bc8aa373bfbe44e91f0625324088be
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -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