Camera pretty much finished
This commit is contained in:
parent
d6c8946e4e
commit
8c36235d36
|
@ -222,8 +222,8 @@ Transform:
|
|||
m_GameObject: {fileID: 163929259}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 2.8726685, y: 0.40448904, z: -1.4757066}
|
||||
m_LocalScale: {x: 10, y: 5.455344, z: 0.5}
|
||||
m_LocalPosition: {x: 2.8726685, y: 0.897, z: -1.4757066}
|
||||
m_LocalScale: {x: 10, y: 4.470458, z: 0.5}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
|
@ -550,8 +550,8 @@ Transform:
|
|||
m_GameObject: {fileID: 1425080745}
|
||||
serializedVersion: 2
|
||||
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
|
||||
m_LocalPosition: {x: 2.8726685, y: 0.40448904, z: -11.059507}
|
||||
m_LocalScale: {x: 10, y: 5.455344, z: 0.5}
|
||||
m_LocalPosition: {x: 2.8726685, y: 0.9099, z: -11.059507}
|
||||
m_LocalScale: {x: 10, y: 4.444636, z: 0.5}
|
||||
m_ConstrainProportionsScale: 0
|
||||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
|
@ -941,6 +941,21 @@ PrefabInstance:
|
|||
propertyPath: m_LocalRotation.z
|
||||
value: -0.1103237
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: sphereRayOffset.y
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: maxSphereRayDistanceOffset
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: maxSphereRayDistanceOffset.y
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5753661378891917460, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: m_LocalRotation.w
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class HideWall : MonoBehaviour
|
||||
|
@ -11,49 +12,61 @@ public class HideWall : MonoBehaviour
|
|||
public Material hitMaterial; // Material when hitting "Wall"
|
||||
|
||||
public float sphereRadius;
|
||||
float maxRayDistance;
|
||||
float maxSphereRayDistance;
|
||||
public Vector3 maxSphereRayDistanceOffset;
|
||||
|
||||
private List<GameObject> prevHitObjects = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
{
|
||||
maxRayDistance = Vector3.Distance(target.transform.position, origin.transform.position) - sphereRadius * 2;
|
||||
maxSphereRayDistance = Vector3.Distance(origin.transform.position, target.transform.position) - (sphereRadius * 2 + 1);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Vector3 direction = (target.transform.position - origin.transform.position).normalized;
|
||||
Vector3 direction = ((target.transform.position + maxSphereRayDistanceOffset) - origin.transform.position).normalized;
|
||||
RaycastHit[] hits = Physics.SphereCastAll(origin.transform.position, sphereRadius, direction, maxSphereRayDistance);
|
||||
|
||||
RaycastHit[] hit;
|
||||
List<GameObject> hitObjectsThisFrame = new List<GameObject>();
|
||||
|
||||
hit = Physics.SphereCastAll(origin.transform.position, sphereRadius, direction, maxRayDistance);
|
||||
|
||||
for (int i = 0; i < hit.Length; i++)
|
||||
// Change material of currently hit objects
|
||||
for (int i = 0; i < hits.Length; i++)
|
||||
{
|
||||
if (hit[i].collider.CompareTag("Wall"))
|
||||
if (hits[i].collider.CompareTag("Wall"))
|
||||
{
|
||||
if (prevObject != null)
|
||||
if (prevObject == hit[i].collider.gameObject)
|
||||
{
|
||||
var renderer = hit[i].collider.GetComponent<Renderer>();
|
||||
var originalMat = renderer.material;
|
||||
var originalColor = originalMat.color;
|
||||
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 0f);
|
||||
renderer.material = originalMat;
|
||||
}
|
||||
else
|
||||
{
|
||||
var renderer = prevObject.GetComponent<Collider>().GetComponent<Renderer>();
|
||||
var originalMat = renderer.material;
|
||||
var originalColor = originalMat.color;
|
||||
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1f);
|
||||
renderer.material = originalMat;
|
||||
}
|
||||
var hitGameObject = hits[i].collider.gameObject;
|
||||
hitObjectsThisFrame.Add(hitGameObject);
|
||||
|
||||
prevObject = hit[i].collider.gameObject;
|
||||
// Change material only if this object wasn't hit last frame
|
||||
if (!prevHitObjects.Contains(hitGameObject))
|
||||
{
|
||||
Renderer renderer = hits[i].collider.GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
renderer.material = hitMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
print(hit[i].collider.gameObject.name);
|
||||
}
|
||||
|
||||
// Restore the material of objects that are not hit this frame but were hit in the previous frame
|
||||
for (int i = 0; i < prevHitObjects.Count; i++)
|
||||
{
|
||||
if (!hitObjectsThisFrame.Contains(prevHitObjects[i]))
|
||||
{
|
||||
Renderer renderer = prevHitObjects[i].GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
renderer.material = defaultMaterial;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the list of previously hit objects
|
||||
prevHitObjects = hitObjectsThisFrame;
|
||||
}
|
||||
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
|
|
Loading…
Reference in New Issue