camera cinemachine

This commit is contained in:
kimrdd 2024-04-20 16:52:39 +02:00
parent 15cb065999
commit 67deee74e3
5 changed files with 1348 additions and 1774 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: fd9f9b61c0ebb324ebc9f929e26706bc
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load Diff

View File

@ -3,27 +3,37 @@ using Cinemachine;
public class CameraController : MonoBehaviour public class CameraController : MonoBehaviour
{ {
//[SerializeField] private CinemachineVirtualCamera cam; [SerializeField] private GameObject cam;
//private CinemachineOrbitalTransposer orbitalTransposer;
//private void Start() public float scrollSpeed;
//{
// orbitalTransposer = cam.GetCinemachineComponent<CinemachineOrbitalTransposer>();
//}
//private void Update() public Vector2 sens;
//{ private Vector2 defaultMaxSpeed;
// if (Input.GetMouseButtonDown(1))
// {
// orbitalTransposer.m_XAxis.m_InputAxisName = "Mouse X";
// //orbitalTransposer.
// }
// if (Input.GetMouseButtonUp(1)) private void Start()
// { {
defaultMaxSpeed *= 0;
}
// orbitalTransposer.m_XAxis.m_InputAxisName = null; private void Update()
{
defaultMaxSpeed = new Vector2(cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed, cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed);
// } if (Input.GetMouseButtonDown(1))
//} {
defaultMaxSpeed = sens;
}
if (Input.GetMouseButtonUp(1))
{
defaultMaxSpeed *= 0;
}
cam.GetComponent<CinemachineFreeLook>().m_XAxis.m_MaxSpeed = defaultMaxSpeed.x;
cam.GetComponent<CinemachineFreeLook>().m_YAxis.m_MaxSpeed = defaultMaxSpeed.y;
float scroll = Input.GetAxis("Mouse ScrollWheel");
cam.GetComponent<CinemachineCameraOffset>().m_Offset.z += scroll * scrollSpeed;
}
} }

View File

@ -2,33 +2,41 @@ using UnityEngine;
public class HideWall : MonoBehaviour public class HideWall : MonoBehaviour
{ {
public float maxRayDistance;
[SerializeField] private GameObject target; [SerializeField] private GameObject target;
[SerializeField] private GameObject origin; [SerializeField] private GameObject origin;
public GameObject prevObject;
public Material defaultMaterial; // Material when not hitting "Wall" public Material defaultMaterial; // Material when not hitting "Wall"
public Material hitMaterial; // Material when hitting "Wall" public Material hitMaterial; // Material when hitting "Wall"
public GameObject prevObject; public float sphereRadius;
float maxRayDistance;
private void Start()
{
maxRayDistance = Vector3.Distance(target.transform.position, origin.transform.position) - sphereRadius * 2;
}
void Update() void Update()
{ {
Vector3 direction = (target.transform.position - origin.transform.position).normalized; Vector3 direction = (target.transform.position - origin.transform.position).normalized;
RaycastHit hit; RaycastHit[] hit;
if (Physics.Raycast(origin.transform.position, direction, out hit, maxRayDistance)) hit = Physics.SphereCastAll(origin.transform.position, sphereRadius, direction, maxRayDistance);
for (int i = 0; i < hit.Length; i++)
{ {
if (hit.collider.CompareTag("Wall")) if (hit[i].collider.CompareTag("Wall"))
{ {
if (prevObject != null) if (prevObject != null)
if (prevObject == hit.collider.gameObject) if (prevObject == hit[i].collider.gameObject)
{ {
var renderer = hit.collider.GetComponent<Renderer>(); var renderer = hit[i].collider.GetComponent<Renderer>();
var originalMat = renderer.material; var originalMat = renderer.material;
var originalColor = originalMat.color; var originalColor = originalMat.color;
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, originalColor.a *0f); originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 0f);
renderer.material = originalMat; renderer.material = originalMat;
} }
else else
@ -36,18 +44,19 @@ public class HideWall : MonoBehaviour
var renderer = prevObject.GetComponent<Collider>().GetComponent<Renderer>(); var renderer = prevObject.GetComponent<Collider>().GetComponent<Renderer>();
var originalMat = renderer.material; var originalMat = renderer.material;
var originalColor = originalMat.color; var originalColor = originalMat.color;
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, originalColor.a + 1f); originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1f);
renderer.material = originalMat; renderer.material = originalMat;
} }
prevObject = hit.collider.gameObject; prevObject = hit[i].collider.gameObject;
} }
print(hit[i].collider.gameObject.name);
} }
} }
private void OnDrawGizmos() private void OnDrawGizmos()
{ {
Gizmos.color = Color.red; Gizmos.color = Color.red;
Gizmos.DrawRay(origin.transform.position, (target.transform.position - origin.transform.position).normalized * maxRayDistance); Gizmos.DrawWireSphere(origin.transform.position, sphereRadius);
} }
} }