first push 2
This commit is contained in:
33
Assets/Scripts/DGemItem.cs
Normal file
33
Assets/Scripts/DGemItem.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DGemItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float decSpeed = 5f;
|
||||
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
collision.gameObject.GetComponent<PlayerMovementController>().SetSpeed(decSpeed);
|
||||
Destroy(this.gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/DGemItem.cs.meta
Normal file
11
Assets/Scripts/DGemItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b81301b367248407f8c53744b655b039
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
33
Assets/Scripts/GemItem.cs
Normal file
33
Assets/Scripts/GemItem.cs
Normal file
@ -0,0 +1,33 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class GemItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private float instantSpeed = 98f;
|
||||
|
||||
|
||||
|
||||
private void OnTriggerEnter(Collider collision)
|
||||
{
|
||||
if (collision.gameObject.CompareTag("Player"))
|
||||
{
|
||||
collision.gameObject.GetComponent<PlayerMovementController>().SetSpeed(instantSpeed);
|
||||
Destroy(this.gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/GemItem.cs.meta
Normal file
11
Assets/Scripts/GemItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1330f6d70036c9847aec81a067a760d0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Inventory.meta
Normal file
8
Assets/Scripts/Inventory.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e4e90b371fb0994083a4dc7b32c70ec
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
73
Assets/Scripts/Inventory/Inventory.cs
Normal file
73
Assets/Scripts/Inventory/Inventory.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Inventory:
|
||||
/// <list type="bullet">Inventory Name: The name of the inventory.</list>
|
||||
/// <list type="bullet">Inventory Size: The amount of size the inventory has.</list>
|
||||
/// <list type="bullet">Invetory Items: List of all items in the inventory. No items in the world are "destroyed"
|
||||
/// instead all items in inventory are disabled, but can be looked up by their item name.</list>
|
||||
/// </summary>
|
||||
public class Inventory : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string inventoryName;
|
||||
[SerializeField]
|
||||
private int inventorySize;
|
||||
[SerializeField]
|
||||
private List<string> inventoryItems;
|
||||
private int inventoryReserved;
|
||||
|
||||
/// <summary>
|
||||
/// Adds item to inventory. Does not disable.
|
||||
/// </summary>
|
||||
/// <param name="item"></param>
|
||||
/// <returns></returns>
|
||||
public bool AddItem(CarryableItem item)
|
||||
{
|
||||
if(item.ItemSize+inventoryReserved > inventorySize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
inventoryItems.Add(item.ItemName);
|
||||
inventoryReserved += item.ItemSize;
|
||||
//item.gameObject.SetActive(false);
|
||||
return true;
|
||||
}
|
||||
private bool FindItemOfName(string name, out CarryableItem item)
|
||||
{
|
||||
//NOTE: May not work. May need to move instead of disable objects.
|
||||
CarryableItem[] items = Resources.FindObjectsOfTypeAll<CarryableItem>();
|
||||
|
||||
foreach (CarryableItem item2 in items)
|
||||
{
|
||||
if (item2.ItemName == name)
|
||||
{
|
||||
|
||||
item = item2;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
item = null;
|
||||
return false;
|
||||
|
||||
}
|
||||
public bool RemoveItem(string name)
|
||||
{
|
||||
|
||||
CarryableItem itemFound;
|
||||
if (FindItemOfName(name,out itemFound))
|
||||
{
|
||||
itemFound.gameObject.SetActive(true);
|
||||
inventoryItems.Remove(itemFound.ItemName);
|
||||
inventoryReserved -= itemFound.ItemSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
11
Assets/Scripts/Inventory/Inventory.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e2003234a0aa11e4797fe8fe9376402f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Item.meta
Normal file
8
Assets/Scripts/Item.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 95bdc0199a7bdb04a9f84c79893bff49
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
16
Assets/Scripts/Item/CarryableItem.cs
Normal file
16
Assets/Scripts/Item/CarryableItem.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public abstract class CarryableItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string itemName;
|
||||
public string ItemName { get { return this.itemName; } }
|
||||
[SerializeField]
|
||||
private int itemSize = 1;
|
||||
public int ItemSize { get { return this.itemSize; } }
|
||||
|
||||
}
|
11
Assets/Scripts/Item/CarryableItem.cs.meta
Normal file
11
Assets/Scripts/Item/CarryableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7beeb2b1c959a8a4a89869ecf33d0f16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
32
Assets/Scripts/Item/HeavyInteractableItem.cs
Normal file
32
Assets/Scripts/Item/HeavyInteractableItem.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class HeavyInteractableItem : InteractableItem
|
||||
{
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void DisableAll()
|
||||
{
|
||||
this.GetComponent<Collider>().enabled = false;
|
||||
}
|
||||
public void EnableAll()
|
||||
{
|
||||
this.GetComponent<Collider>().enabled = true;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
BaseFixedUpdate();
|
||||
//print("Alpha Target:"+ base.target_alpha);
|
||||
}
|
||||
}
|
11
Assets/Scripts/Item/HeavyInteractableItem.cs.meta
Normal file
11
Assets/Scripts/Item/HeavyInteractableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 051ddd707f17e1040b0fbe15645f75b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
78
Assets/Scripts/Item/InteractableItem.cs
Normal file
78
Assets/Scripts/Item/InteractableItem.cs
Normal file
@ -0,0 +1,78 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
[RequireComponent(typeof(Rigidbody))]
|
||||
public class InteractableItem : CarryableItem
|
||||
{
|
||||
|
||||
|
||||
[SerializeField]
|
||||
private Canvas interactionCanvas;
|
||||
private TMP_Text[] interaction_texts;
|
||||
private Image[] interaction_images;
|
||||
protected float target_alpha = 0;
|
||||
[SerializeField]
|
||||
protected bool canPickup = false;
|
||||
protected bool isEnabled = false;
|
||||
|
||||
public bool CanPickup { get { return canPickup; } }
|
||||
public bool IsEnabled { get { return isEnabled; } }
|
||||
|
||||
public void Enable()
|
||||
{
|
||||
print("Enabled!");
|
||||
interactionCanvas.transform.LookAt((GameObject.FindGameObjectWithTag("MainCamera").transform.position));
|
||||
interactionCanvas.transform.Rotate(0, 180, 0);
|
||||
target_alpha = 1;
|
||||
isEnabled = true;
|
||||
}
|
||||
|
||||
public void Disable()
|
||||
{
|
||||
print("Disabled!");
|
||||
target_alpha = 0;
|
||||
isEnabled = true;
|
||||
}
|
||||
public void Interact()
|
||||
{
|
||||
|
||||
}
|
||||
protected void BaseAwake()
|
||||
{
|
||||
interaction_texts = interactionCanvas.GetComponentsInChildren<TMP_Text>();
|
||||
interaction_images = interactionCanvas.GetComponentsInChildren<Image>();
|
||||
foreach (TMP_Text text in interaction_texts)
|
||||
{
|
||||
text.color = new Color(text.color.r, text.color.g, text.color.b, 0);
|
||||
}
|
||||
foreach (Image image in interaction_images)
|
||||
{
|
||||
image.color = new Color(image.color.r, image.color.g, image.color.b, 0);
|
||||
}
|
||||
}
|
||||
protected void BaseFixedUpdate()
|
||||
{
|
||||
foreach (TMP_Text text in interaction_texts)
|
||||
{
|
||||
text.color = Color.Lerp(new Color(text.color.r, text.color.g, text.color.b, text.color.a), new Color(text.color.r, text.color.g, text.color.b, target_alpha), 10 * Time.deltaTime);
|
||||
}
|
||||
foreach (Image image in interaction_images)
|
||||
{
|
||||
image.color = Color.Lerp(new Color(image.color.r, image.color.g, image.color.b, image.color.a), new Color(image.color.r, image.color.g, image.color.b, target_alpha), 10 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BaseAwake();
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
BaseFixedUpdate();
|
||||
}
|
||||
}
|
11
Assets/Scripts/Item/InteractableItem.cs.meta
Normal file
11
Assets/Scripts/Item/InteractableItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1b92dbad437a8241a0eef54af2becd7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
20
Assets/Scripts/Item/KeyItem.cs
Normal file
20
Assets/Scripts/Item/KeyItem.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class KeyItem : InteractableItem
|
||||
{
|
||||
[SerializeField]
|
||||
private string keyName;
|
||||
public string KeyName { get { return keyName; } }
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
BaseAwake();
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Item/KeyItem.cs.meta
Normal file
11
Assets/Scripts/Item/KeyItem.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb21435ed07266d488d3c4116207dfd9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
8
Assets/Scripts/Player.meta
Normal file
8
Assets/Scripts/Player.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ddb4b247b17b8d45a178b196a32f351
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
57
Assets/Scripts/Player/CameraController.cs
Normal file
57
Assets/Scripts/Player/CameraController.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
|
||||
private float mouseX = 0;
|
||||
private float mouseY;
|
||||
[SerializeField]
|
||||
private Camera cam;
|
||||
[SerializeField]
|
||||
private Transform target;
|
||||
|
||||
private Vector3 offset;
|
||||
|
||||
private Vector3 forward= Vector3.zero;
|
||||
private Vector3 right = Vector3.zero;
|
||||
public Vector3 Forward { get { return this.forward; } }
|
||||
public Vector3 Right { get { return this.right; } }
|
||||
|
||||
private float originalDist = 0;
|
||||
private float newDist = 0;
|
||||
[SerializeField]
|
||||
private bool isChild = false;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
GetMouseLook();
|
||||
//if(target!=null&&!isChild)
|
||||
//transform.position = target.transform.position+offset;
|
||||
forward = new Vector3(cam.transform.forward.x, target.transform.forward.y, cam.transform.forward.z);
|
||||
right = new Vector3(cam.transform.right.x, target.transform.right.y, cam.transform.right.z);
|
||||
}
|
||||
private void GetMouseLook()
|
||||
{
|
||||
//mouseX = Input.GetAxis("Mouse X");
|
||||
//mouseY = Input.GetAxis("Mouse Y");
|
||||
|
||||
//transform.Rotate(0, mouseX * Time.deltaTime * 180f, 0);
|
||||
//cam.transform.parent.parent.transform.Rotate(mouseY * Time.deltaTime * 180f, 0, 0);
|
||||
|
||||
Cursor.visible = false;
|
||||
Cursor.lockState = CursorLockMode.Locked;
|
||||
}
|
||||
|
||||
|
||||
}
|
11
Assets/Scripts/Player/CameraController.cs.meta
Normal file
11
Assets/Scripts/Player/CameraController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3847c9aa2dda4d64f84842c3cc880d7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
60
Assets/Scripts/Player/PlayerAnimationController.cs
Normal file
60
Assets/Scripts/Player/PlayerAnimationController.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerAnimationController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Animator animController;
|
||||
[SerializeField]
|
||||
private string runningParameter;
|
||||
[SerializeField]
|
||||
private string runningSpeedParameter;
|
||||
[SerializeField]
|
||||
private string sideStepSpeedParameter;
|
||||
|
||||
private float runningSpeed;
|
||||
private float sideStepSpeed;
|
||||
|
||||
private bool isRunning;
|
||||
private bool movementInterrupt = false;
|
||||
[SerializeField]
|
||||
private PlayerInteractionHandler interactionHandler;
|
||||
|
||||
|
||||
public void Animate(Vector2 movement,bool jump,bool isMoving)
|
||||
{
|
||||
animController.SetFloat(runningSpeedParameter, movement.magnitude);
|
||||
animController.SetBool(runningParameter,isMoving);
|
||||
//animController.SetFloat(sideStepSpeedParameter, movement.x);
|
||||
|
||||
}
|
||||
public void Animate(PlayerQuickAnimationType animation)
|
||||
{
|
||||
switch(animation)
|
||||
{
|
||||
case PlayerQuickAnimationType.Grab:
|
||||
print("grabbing...");
|
||||
break;
|
||||
case PlayerQuickAnimationType.Shoot:
|
||||
print("shooting...");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
animController.SetBool("IsCarrying", interactionHandler.IsCarrying);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PlayerAnimationType {Movement,Action}
|
||||
public enum PlayerQuickAnimationType { Grab,Shoot}
|
11
Assets/Scripts/Player/PlayerAnimationController.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerAnimationController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cabfb8d71f6bc7041830b669859f203a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
117
Assets/Scripts/Player/PlayerInteractionHandler.cs
Normal file
117
Assets/Scripts/Player/PlayerInteractionHandler.cs
Normal file
@ -0,0 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public class PlayerInteractionHandler : MonoBehaviour
|
||||
{
|
||||
private List<InteractableItem> itemsInRange= new List<InteractableItem>();
|
||||
private List<HeavyInteractableItem> heavyItemsInRange = new List<HeavyInteractableItem>();
|
||||
private Inventory invent;
|
||||
[SerializeField]
|
||||
private Light flashlight;
|
||||
[SerializeField]
|
||||
private GameObject flashlight3D;
|
||||
[SerializeField]
|
||||
private int materialIndex = 1;
|
||||
private Material selMaterial;
|
||||
private Color initColor;
|
||||
|
||||
private HeavyInteractableItem heavyInvent;
|
||||
public bool IsCarrying { get { return heavyInvent !=null; } }
|
||||
[SerializeField]
|
||||
private Transform carryingPos;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
invent = this.transform.parent.GetComponent<Inventory>();
|
||||
initColor = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].GetColor("_BaseColor");
|
||||
selMaterial = flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex];
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
//
|
||||
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)
|
||||
{
|
||||
|
||||
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 (Input.GetButtonDown("Fire2"))
|
||||
{
|
||||
flashlight.gameObject.SetActive(!flashlight.gameObject.activeSelf);
|
||||
if (flashlight.gameObject.activeSelf)
|
||||
{
|
||||
flashlight3D.GetComponent<MeshRenderer>().materials[materialIndex].SetColor("_BaseColor", initColor);
|
||||
selMaterial.SetColor("_EmissionColor", new Color(0, 0, 0, 0));
|
||||
flashlight3D.gameObject.SetActive(true);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if(other.gameObject.GetComponent<InteractableItem>() != null)
|
||||
{
|
||||
InteractableItem item = other.gameObject.GetComponent<InteractableItem>();
|
||||
if(item is InteractableItem && item is not HeavyInteractableItem)
|
||||
{
|
||||
((InteractableItem)item).Enable();
|
||||
itemsInRange.Add(item);
|
||||
}else if(item is HeavyInteractableItem)
|
||||
{
|
||||
((HeavyInteractableItem)item).Enable();
|
||||
heavyItemsInRange.Add((HeavyInteractableItem)item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.gameObject.GetComponent<InteractableItem>() != null)
|
||||
{
|
||||
InteractableItem item = other.gameObject.GetComponent<InteractableItem>();
|
||||
if (item is InteractableItem && item is not HeavyInteractableItem)
|
||||
{
|
||||
((InteractableItem)item).Disable();
|
||||
itemsInRange.Remove(item);
|
||||
|
||||
}
|
||||
else if (item is HeavyInteractableItem)
|
||||
{
|
||||
((HeavyInteractableItem)item).Disable();
|
||||
//itemsInRange.Remove((HeavyInteractableItem)(item));
|
||||
heavyItemsInRange.Remove((HeavyInteractableItem)item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerInteractionHandler.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerInteractionHandler.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cc1d606aab4ac0841954339b67bc1fb4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
88
Assets/Scripts/Player/PlayerMovementController.cs
Normal file
88
Assets/Scripts/Player/PlayerMovementController.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovementController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private PlayerAnimationController animcontroller;
|
||||
|
||||
private float x = 0;
|
||||
private float y = 0;
|
||||
private float mouseX = 0;
|
||||
|
||||
private bool isRunning = false;
|
||||
[SerializeField]
|
||||
private CharacterController ccontroller;
|
||||
|
||||
[SerializeField]
|
||||
private CameraController cameraController;
|
||||
|
||||
[SerializeField]
|
||||
private float speed = 1f;
|
||||
[SerializeField]
|
||||
private float sideSpeed = 0.5f;
|
||||
|
||||
[SerializeField]
|
||||
private float animatedRotationSpeed = 5f;
|
||||
|
||||
|
||||
|
||||
|
||||
private Vector3 lookingDirectionVector;
|
||||
private void GetMovementOld()
|
||||
{
|
||||
x = Input.GetAxis("Horizontal");
|
||||
y = Input.GetAxis("Vertical");
|
||||
isRunning = (Mathf.Abs(y) > 0.1f || Mathf.Abs(x) > 0.1f);
|
||||
}
|
||||
private void MovePlayer()
|
||||
{
|
||||
Vector3 movement = Vector3.zero;
|
||||
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;
|
||||
ccontroller.Move(movement);
|
||||
}
|
||||
|
||||
public void SetSpeed(float speed)
|
||||
{
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
private void GetJumpOld()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
GetMovementOld();
|
||||
MovePlayer();
|
||||
|
||||
animcontroller.Animate(new Vector2(x, y), false,isRunning);
|
||||
|
||||
this.lookingDirectionVector = ((cameraController.Forward * y) + cameraController.Right * x).normalized;
|
||||
if (isRunning && !Input.GetMouseButton(1))
|
||||
{
|
||||
SlowLookAt(this.lookingDirectionVector);
|
||||
}
|
||||
}
|
||||
|
||||
void SlowLookAt(Vector3 targetVector)
|
||||
{
|
||||
Vector3 relativePos = targetVector;
|
||||
Quaternion toRotation = Quaternion.LookRotation(relativePos);
|
||||
|
||||
transform.rotation = Quaternion.Lerp(transform.rotation, toRotation, animatedRotationSpeed * Time.deltaTime);
|
||||
|
||||
}
|
||||
}
|
11
Assets/Scripts/Player/PlayerMovementController.cs.meta
Normal file
11
Assets/Scripts/Player/PlayerMovementController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 04d9fbdb37200704a9166659474a658a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Reference in New Issue
Block a user