mirror of
https://github.com/Project-Redacted/project-hampter.git
synced 2025-06-13 14:13:14 +00:00
Update :3
This commit is contained in:
parent
1f50b3f262
commit
6bbd56a5cf
759 changed files with 269694 additions and 37600 deletions
34
Assets/Scripts/CameraRender.cs
Normal file
34
Assets/Scripts/CameraRender.cs
Normal file
|
@ -0,0 +1,34 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class CameraRender : MonoBehaviour
|
||||
{
|
||||
private Camera cam;
|
||||
private Bounds camBounds;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
cam = GetComponent<Camera>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// Calculate the camera's view frustum bounds
|
||||
camBounds = new Bounds(cam.transform.position, new Vector3(cam.farClipPlane * 2, cam.farClipPlane * 2, cam.farClipPlane * 2));
|
||||
|
||||
// Loop through all the game objects that have a renderer component
|
||||
foreach (Renderer renderer in FindObjectsOfType<Renderer>())
|
||||
{
|
||||
// Check if the renderer bounds are within the camera's view
|
||||
if (camBounds.Intersects(renderer.bounds))
|
||||
{
|
||||
// Enable the renderer if it's within the camera's view
|
||||
renderer.enabled = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable the renderer if it's outside the camera's view
|
||||
renderer.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/CameraRender.cs.meta
Normal file
11
Assets/Scripts/CameraRender.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6e7eaaa21e7cd0640806666a8bf4738d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
29
Assets/Scripts/Flashlight.cs
Normal file
29
Assets/Scripts/Flashlight.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Flashlight : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Light flashlight; // Reference to the flashlight Light component
|
||||
public KeyCode toggleKey = KeyCode.E; // Key to toggle the flashlight on/off
|
||||
private bool isOn = false; // Flag to keep track of whether the flashlight is on or off
|
||||
public AudioSource audioSource;
|
||||
private void Start()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
flashlight = GetComponentInChildren<Light>();
|
||||
flashlight.enabled = false;
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
// Check if the toggle key is pressed
|
||||
if (Input.GetKeyDown(toggleKey))
|
||||
{
|
||||
// Toggle the flashlight on/off
|
||||
isOn = !isOn;
|
||||
flashlight.enabled = isOn;
|
||||
audioSource.Play();
|
||||
|
||||
//audioClip = GetComponent<AudioClip>();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/Flashlight.cs.meta
Normal file
11
Assets/Scripts/Flashlight.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ba36bb29389e9394290ba8b76aa6418d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
15
Assets/Scripts/LoadNextScene.cs
Normal file
15
Assets/Scripts/LoadNextScene.cs
Normal file
|
@ -0,0 +1,15 @@
|
|||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class LoadNextScene : MonoBehaviour
|
||||
{
|
||||
public string nextSceneName; // the name of the next scene to load
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Player"))
|
||||
{
|
||||
SceneManager.LoadScene(nextSceneName); // load the next scene
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LoadNextScene.cs.meta
Normal file
11
Assets/Scripts/LoadNextScene.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f447fc095c530cd45a8b33c26237b850
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
67
Assets/Scripts/MeshCombiner.cs
Normal file
67
Assets/Scripts/MeshCombiner.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
using UnityEngine;
|
||||
using System.Collections.Generic;
|
||||
|
||||
public class MeshCombiner : MonoBehaviour
|
||||
{
|
||||
public string tagToCombine;
|
||||
public bool destroyAfterCombine;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Invoke("CombineMeshes", 0.5f);
|
||||
//CombineMeshes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void CombineMeshes()
|
||||
{
|
||||
|
||||
Debug.Log("started");
|
||||
// Find all game objects with the specified tag
|
||||
GameObject[] taggedObjects = GameObject.FindGameObjectsWithTag("Wall");
|
||||
/*
|
||||
List<GameObject> taggedObjectsList = new List<GameObject>();
|
||||
foreach(GameObject g in upperTaggedObjects)
|
||||
{
|
||||
foreach(MeshFilter mr in g.GetComponents<MeshFilter>())
|
||||
{
|
||||
taggedObjectsList.Add(mr.gameObject);
|
||||
Debug.Log("Added");
|
||||
}
|
||||
}
|
||||
taggedObjectsList.TrimExcess();
|
||||
GameObject[] taggedObjects = taggedObjectsList.ToArray();
|
||||
*/
|
||||
Debug.Log(taggedObjects.Length);
|
||||
// Combine all the meshes into a single mesh
|
||||
Mesh combinedMesh = new Mesh();
|
||||
CombineInstance[] combineInstances = new CombineInstance[taggedObjects.Length];
|
||||
for (int i = 0; i < taggedObjects.Length; i++)
|
||||
{
|
||||
combineInstances[i].mesh = taggedObjects[i].GetComponent<MeshFilter>().sharedMesh;
|
||||
combineInstances[i].transform = taggedObjects[i].transform.localToWorldMatrix;
|
||||
}
|
||||
combinedMesh.CombineMeshes(combineInstances, true);
|
||||
|
||||
// Create a new game object to hold the combined mesh
|
||||
GameObject combinedObject = new GameObject(tagToCombine + "_Combined");
|
||||
combinedObject.transform.position = Vector3.zero;
|
||||
combinedObject.transform.rotation = Quaternion.identity;
|
||||
|
||||
// Add a mesh filter and renderer to the combined game object
|
||||
MeshFilter meshFilter = combinedObject.AddComponent<MeshFilter>();
|
||||
MeshRenderer meshRenderer = combinedObject.AddComponent<MeshRenderer>();
|
||||
meshFilter.mesh = combinedMesh;
|
||||
meshRenderer.material = taggedObjects[0].GetComponent<Renderer>().sharedMaterial;
|
||||
|
||||
// Destroy the original game objects if specified
|
||||
if (destroyAfterCombine)
|
||||
{
|
||||
foreach (GameObject obj in taggedObjects)
|
||||
{
|
||||
Destroy(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/MeshCombiner.cs.meta
Normal file
11
Assets/Scripts/MeshCombiner.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb517f0df8d32ce4d93951d22bcec53c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
66
Assets/Scripts/ObjectGrab.cs
Normal file
66
Assets/Scripts/ObjectGrab.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ObjectGrab : MonoBehaviour
|
||||
{
|
||||
private Rigidbody objectRigidbody;
|
||||
private Transform objectGrabPointTransform;
|
||||
public float ThrowForce = 5;
|
||||
|
||||
private Vector3 StartPosition;
|
||||
private void Awake()
|
||||
{
|
||||
objectRigidbody = GetComponent<Rigidbody>();
|
||||
StartPosition = transform.position;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if(transform.position.y < -5)
|
||||
{
|
||||
ResetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Grab(Transform objectGrabPointTransform)
|
||||
{
|
||||
//this.objectGrabPointTransform = objectGrabPointTransform;
|
||||
this.transform.parent = objectGrabPointTransform;
|
||||
this.transform.localPosition = new Vector3(0, 0, 0);
|
||||
|
||||
objectRigidbody.useGravity = false;
|
||||
objectRigidbody.isKinematic = true;
|
||||
this.GetComponent<Collider>().enabled = false;
|
||||
Move m = GetComponentInChildren<Move>();
|
||||
if(m != null)
|
||||
{
|
||||
m.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Throw(Vector3 direcction)
|
||||
{
|
||||
this.transform.parent = null;
|
||||
objectRigidbody.useGravity = true;
|
||||
objectRigidbody.isKinematic = false;
|
||||
this.GetComponent<Collider>().enabled = true;
|
||||
objectRigidbody.AddForce(direcction * ThrowForce, ForceMode.Impulse);
|
||||
}
|
||||
|
||||
private void FixedUpdate(){
|
||||
|
||||
if (objectGrabPointTransform != null){
|
||||
|
||||
objectRigidbody.MovePosition(objectGrabPointTransform.position);
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetPosition()
|
||||
{
|
||||
transform.position = StartPosition;
|
||||
objectRigidbody.velocity = new Vector3(0, 0, 0);
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/ObjectGrab.cs.meta
Normal file
11
Assets/Scripts/ObjectGrab.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 543f15b85e3d9f94db7856b190331b83
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
55
Assets/Scripts/PickUpObject.cs
Normal file
55
Assets/Scripts/PickUpObject.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PickUpObject : MonoBehaviour
|
||||
{
|
||||
public Transform hand;
|
||||
private Transform heldObject;
|
||||
private float pickupDistance = 5.0f;
|
||||
private bool isHoldingObject = false;
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.F) && !isHoldingObject)
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, pickupDistance))
|
||||
{
|
||||
|
||||
ObjectGrab OG = hit.transform.GetComponent<ObjectGrab>();
|
||||
if(OG != null)
|
||||
{
|
||||
OG.Grab(hand);
|
||||
|
||||
isHoldingObject = true;
|
||||
heldObject = hit.transform;
|
||||
}
|
||||
|
||||
|
||||
if (hit.transform.CompareTag("PickUpObject"))
|
||||
{
|
||||
/*
|
||||
heldObject = hit.transform;
|
||||
heldObject.GetComponent<Rigidbody>().isKinematic = true;
|
||||
heldObject.SetParent(transform);
|
||||
heldObject.localPosition = Vector3.zero;
|
||||
*/
|
||||
isHoldingObject = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.G) && isHoldingObject)
|
||||
{
|
||||
heldObject.GetComponent<ObjectGrab>().Throw(Camera.main.transform.forward);
|
||||
heldObject = null;
|
||||
isHoldingObject = false;
|
||||
}
|
||||
|
||||
if(heldObject != null)
|
||||
{
|
||||
heldObject.rotation = Quaternion.Lerp(heldObject.rotation, Camera.main.transform.rotation, 5 * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/PickUpObject.cs.meta
Normal file
11
Assets/Scripts/PickUpObject.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 36a3bae5584149749984069c1559d5b6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue