Camera smoothing
This commit is contained in:
parent
0db4c49568
commit
2ace1d04ad
|
@ -135,6 +135,7 @@ GameObject:
|
|||
- component: {fileID: 163929262}
|
||||
- component: {fileID: 163929261}
|
||||
- component: {fileID: 163929260}
|
||||
- component: {fileID: 163929264}
|
||||
m_Layer: 0
|
||||
m_Name: Cube (3)
|
||||
m_TagString: Wall
|
||||
|
@ -228,6 +229,18 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &163929264
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 163929259}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &310810784
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -240,6 +253,7 @@ GameObject:
|
|||
- component: {fileID: 310810787}
|
||||
- component: {fileID: 310810786}
|
||||
- component: {fileID: 310810785}
|
||||
- component: {fileID: 310810789}
|
||||
m_Layer: 0
|
||||
m_Name: Cube (1)
|
||||
m_TagString: Wall
|
||||
|
@ -333,6 +347,18 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &310810789
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 310810784}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1257773688
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -451,6 +477,12 @@ MonoBehaviour:
|
|||
m_LightCookieSize: {x: 1, y: 1}
|
||||
m_LightCookieOffset: {x: 0, y: 0}
|
||||
m_SoftShadowQuality: 0
|
||||
--- !u!1 &1267316003 stripped
|
||||
GameObject:
|
||||
m_CorrespondingSourceObject: {fileID: 7435709693246867821, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
m_PrefabInstance: {fileID: 1774990605473331699}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
--- !u!1 &1425080745
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -463,6 +495,7 @@ GameObject:
|
|||
- component: {fileID: 1425080748}
|
||||
- component: {fileID: 1425080747}
|
||||
- component: {fileID: 1425080746}
|
||||
- component: {fileID: 1425080750}
|
||||
m_Layer: 0
|
||||
m_Name: Cube (4)
|
||||
m_TagString: Wall
|
||||
|
@ -556,6 +589,18 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1425080750
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1425080745}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1696531491
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -605,6 +650,7 @@ GameObject:
|
|||
- component: {fileID: 1786067372}
|
||||
- component: {fileID: 1786067371}
|
||||
- component: {fileID: 1786067370}
|
||||
- component: {fileID: 1786067374}
|
||||
m_Layer: 0
|
||||
m_Name: Cube (2)
|
||||
m_TagString: Wall
|
||||
|
@ -698,6 +744,18 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1786067374
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1786067369}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1820565102
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -710,6 +768,7 @@ GameObject:
|
|||
- component: {fileID: 1820565106}
|
||||
- component: {fileID: 1820565105}
|
||||
- component: {fileID: 1820565104}
|
||||
- component: {fileID: 1820565107}
|
||||
m_Layer: 0
|
||||
m_Name: Cube (5)
|
||||
m_TagString: Wall
|
||||
|
@ -803,6 +862,18 @@ MeshFilter:
|
|||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1820565102}
|
||||
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
|
||||
--- !u!114 &1820565107
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1820565102}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1 &1915595172
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -815,6 +886,7 @@ GameObject:
|
|||
- component: {fileID: 1915595175}
|
||||
- component: {fileID: 1915595174}
|
||||
- component: {fileID: 1915595173}
|
||||
- component: {fileID: 1915595177}
|
||||
m_Layer: 0
|
||||
m_Name: Cube
|
||||
m_TagString: Wall
|
||||
|
@ -908,6 +980,18 @@ Transform:
|
|||
m_Children: []
|
||||
m_Father: {fileID: 1696531492}
|
||||
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
|
||||
--- !u!114 &1915595177
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 1915595172}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: c2cdf8a35ccaacc4695675d2ada4aecf, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
--- !u!1001 &1774990605473331699
|
||||
PrefabInstance:
|
||||
m_ObjectHideFlags: 0
|
||||
|
@ -921,6 +1005,191 @@ PrefabInstance:
|
|||
propertyPath: m_Name
|
||||
value: Cinemachine
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: fadeSpeed
|
||||
value: 5.05
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: hideFadeSpeed
|
||||
value: 7
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3313768392743891090, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: showFadeSpeed
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: cam
|
||||
value:
|
||||
objectReference: {fileID: 1267316003}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: sens.x
|
||||
value: 300
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: sens.y
|
||||
value: 3
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: scrollSpeed
|
||||
value: 2
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: stopAfterTime
|
||||
value: 15
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: stopStiffness
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: decelerationMultiplier
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.size
|
||||
value: 4
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].time
|
||||
value: 0.2991759
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].time
|
||||
value: 0.6705839
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].time
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].value
|
||||
value: 0.51186574
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].value
|
||||
value: 0.6387135
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].value
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[0].inSlope
|
||||
value: 1.710919
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].inSlope
|
||||
value: 0.50856996
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].inSlope
|
||||
value: 0.078333884
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].inSlope
|
||||
value: 1.0967482
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[0].outSlope
|
||||
value: 1.710919
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].inWeight
|
||||
value: 1
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].outSlope
|
||||
value: 0.50856996
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].inWeight
|
||||
value: 0.37746048
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].outSlope
|
||||
value: 0.078333884
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].inWeight
|
||||
value: 0.33333334
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].outSlope
|
||||
value: 1.0967482
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[0].outWeight
|
||||
value: 0.33333334
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].outWeight
|
||||
value: 0.30844653
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].outWeight
|
||||
value: 0.33333334
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[0].tangentMode
|
||||
value: 34
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[1].tangentMode
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[2].tangentMode
|
||||
value: 0
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 3837216061230793568, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: curve.m_Curve.Array.data[3].tangentMode
|
||||
value: 34
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5664717836218291588, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: m_XAxis.m_DecelTime
|
||||
value: 0.25
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 5664717836218291588, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: m_YAxis.m_DecelTime
|
||||
value: 0.25
|
||||
objectReference: {fileID: 0}
|
||||
- target: {fileID: 8882344377078016156, guid: fd9f9b61c0ebb324ebc9f929e26706bc,
|
||||
type: 3}
|
||||
propertyPath: m_LocalPosition.x
|
||||
|
|
|
@ -1,15 +1,21 @@
|
|||
using UnityEngine;
|
||||
using Cinemachine;
|
||||
using System.Collections;
|
||||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private GameObject cam;
|
||||
|
||||
public float scrollSpeed;
|
||||
public float stopAfterTime = 0.25f;
|
||||
public AnimationCurve curve = new AnimationCurve(new Keyframe(0f, 0f, 1f, 1f), new Keyframe(1f, 1f, 1f, 1f));
|
||||
[Range(1f, 0f)] public float decelerationMultiplier;
|
||||
|
||||
public Vector2 sens;
|
||||
private Vector2 defaultMaxSpeed;
|
||||
|
||||
private float timer;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
defaultMaxSpeed *= 0;
|
||||
|
@ -17,16 +23,24 @@ public class CameraController : MonoBehaviour
|
|||
|
||||
private void Update()
|
||||
{
|
||||
defaultMaxSpeed = new Vector2(cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed, cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed);
|
||||
//defaultMaxSpeed = new Vector2(cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed, cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed);
|
||||
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
defaultMaxSpeed = sens;
|
||||
|
||||
// Enable mouse input
|
||||
cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_InputAxisName = "Mouse X";
|
||||
cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_InputAxisName = "Mouse Y";
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(1))
|
||||
{
|
||||
defaultMaxSpeed *= 0;
|
||||
timer = 0;
|
||||
|
||||
// Disable mouse input
|
||||
cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_InputAxisName = "";
|
||||
cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_InputAxisName = "";
|
||||
}
|
||||
|
||||
cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed = defaultMaxSpeed.x;
|
||||
|
@ -35,5 +49,11 @@ public class CameraController : MonoBehaviour
|
|||
float scroll = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
cam.GetComponent<CinemachineCameraOffset>().m_Offset.z += scroll * scrollSpeed;
|
||||
|
||||
|
||||
timer += Time.deltaTime;
|
||||
float evalTime = timer / stopAfterTime;
|
||||
if (!Input.GetMouseButton(1))
|
||||
defaultMaxSpeed = Vector2.LerpUnclamped(defaultMaxSpeed, Vector2.zero, curve.Evaluate(evalTime));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,18 +3,16 @@ using UnityEngine;
|
|||
|
||||
public class HideWall : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private GameObject target;
|
||||
[SerializeField] private GameObject origin;
|
||||
public GameObject prevObject;
|
||||
|
||||
public Material defaultMaterial; // Material when not hitting "Wall"
|
||||
public Material hitMaterial; // Material when hitting "Wall"
|
||||
[Range(1f, 10f)] public float hideFadeSpeed;
|
||||
[Range(1f, 10f)] public float showFadeSpeed;
|
||||
|
||||
public float sphereRadius;
|
||||
float maxSphereRayDistance;
|
||||
public Vector3 maxSphereRayDistanceOffset;
|
||||
|
||||
float maxSphereRayDistance;
|
||||
private List<GameObject> prevHitObjects = new List<GameObject>();
|
||||
|
||||
private void Start()
|
||||
|
@ -29,44 +27,36 @@ public class HideWall : MonoBehaviour
|
|||
|
||||
List<GameObject> hitObjectsThisFrame = new List<GameObject>();
|
||||
|
||||
// Change material of currently hit objects
|
||||
for (int i = 0; i < hits.Length; i++)
|
||||
{
|
||||
if (hits[i].collider.CompareTag("Wall"))
|
||||
if (hits[i].collider != null && hits[i].collider.CompareTag("Wall"))
|
||||
{
|
||||
var hitGameObject = hits[i].collider.gameObject;
|
||||
hitObjectsThisFrame.Add(hitGameObject);
|
||||
|
||||
// Change material only if this object wasn't hit last frame
|
||||
if (!prevHitObjects.Contains(hitGameObject))
|
||||
var wallOpacity = hitGameObject.GetComponent<WallOpacity>();
|
||||
if (wallOpacity != null && !prevHitObjects.Contains(hitGameObject))
|
||||
{
|
||||
Renderer renderer = hits[i].collider.GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
renderer.material = hitMaterial;
|
||||
}
|
||||
wallOpacity.HideWall(hideFadeSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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++)
|
||||
foreach (var prevHitObject in prevHitObjects)
|
||||
{
|
||||
if (!hitObjectsThisFrame.Contains(prevHitObjects[i]))
|
||||
if (!hitObjectsThisFrame.Contains(prevHitObject))
|
||||
{
|
||||
Renderer renderer = prevHitObjects[i].GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
var wallOpacity = prevHitObject.GetComponent<WallOpacity>();
|
||||
if (wallOpacity != null)
|
||||
{
|
||||
renderer.material = defaultMaterial;
|
||||
wallOpacity.ShowWall(showFadeSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update the list of previously hit objects
|
||||
prevHitObjects = hitObjectsThisFrame;
|
||||
}
|
||||
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WallOpacity : MonoBehaviour
|
||||
{
|
||||
private float t;
|
||||
private bool isShowing = true;
|
||||
|
||||
private float showFadeSpeed;
|
||||
private float hideFadeSpeed;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
t = 1;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isShowing)
|
||||
{
|
||||
t += Time.deltaTime * showFadeSpeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
t -= Time.deltaTime * hideFadeSpeed;
|
||||
}
|
||||
t = Mathf.Clamp(t, 0, 1);
|
||||
|
||||
Renderer renderer = GetComponent<Renderer>();
|
||||
if (renderer != null)
|
||||
{
|
||||
var originalMat = renderer.material;
|
||||
var originalColor = originalMat.color;
|
||||
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, t);
|
||||
renderer.material = originalMat;
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowWall(float speed)
|
||||
{
|
||||
isShowing = true;
|
||||
showFadeSpeed = speed;
|
||||
}
|
||||
|
||||
public void HideWall(float speed)
|
||||
{
|
||||
isShowing = false;
|
||||
hideFadeSpeed = speed;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c2cdf8a35ccaacc4695675d2ada4aecf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,10 @@
|
|||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Assets
|
||||
{
|
||||
public static class FloatExtensions
|
||||
{
|
||||
public static float Clamp(this float x, float min, float max) => Mathf.Clamp(x, min, max);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 92c9a051ffde8174690f03cc2c3d547b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Reference in New Issue