camera cinemachine
This commit is contained in:
parent
15cb065999
commit
67deee74e3
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd9f9b61c0ebb324ebc9f929e26706bc
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
|
@ -3,27 +3,37 @@ using Cinemachine;
|
|||
|
||||
public class CameraController : MonoBehaviour
|
||||
{
|
||||
//[SerializeField] private CinemachineVirtualCamera cam;
|
||||
//private CinemachineOrbitalTransposer orbitalTransposer;
|
||||
[SerializeField] private GameObject cam;
|
||||
|
||||
//private void Start()
|
||||
//{
|
||||
// orbitalTransposer = cam.GetCinemachineComponent<CinemachineOrbitalTransposer>();
|
||||
//}
|
||||
public float scrollSpeed;
|
||||
|
||||
//private void Update()
|
||||
//{
|
||||
// if (Input.GetMouseButtonDown(1))
|
||||
// {
|
||||
// orbitalTransposer.m_XAxis.m_InputAxisName = "Mouse X";
|
||||
// //orbitalTransposer.
|
||||
// }
|
||||
public Vector2 sens;
|
||||
private Vector2 defaultMaxSpeed;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,33 +2,41 @@ using UnityEngine;
|
|||
|
||||
public class HideWall : MonoBehaviour
|
||||
{
|
||||
public float maxRayDistance;
|
||||
|
||||
[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"
|
||||
|
||||
public GameObject prevObject;
|
||||
public float sphereRadius;
|
||||
float maxRayDistance;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
maxRayDistance = Vector3.Distance(target.transform.position, origin.transform.position) - sphereRadius * 2;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
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 == 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 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;
|
||||
}
|
||||
else
|
||||
|
@ -36,18 +44,19 @@ public class HideWall : MonoBehaviour
|
|||
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, originalColor.a + 1f);
|
||||
originalMat.color = new Color(originalColor.r, originalColor.g, originalColor.b, 1f);
|
||||
renderer.material = originalMat;
|
||||
}
|
||||
|
||||
prevObject = hit.collider.gameObject;
|
||||
prevObject = hit[i].collider.gameObject;
|
||||
}
|
||||
print(hit[i].collider.gameObject.name);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
Gizmos.color = Color.red;
|
||||
Gizmos.DrawRay(origin.transform.position, (target.transform.position - origin.transform.position).normalized * maxRayDistance);
|
||||
Gizmos.DrawWireSphere(origin.transform.position, sphereRadius);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue