Building city
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraPlayerFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _player;
|
||||
|
||||
private Vector3 _cameraOffset;
|
||||
|
||||
private Transform _obstruction;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0.01f, 1.0f)]
|
||||
private float _smoothFactor = 0.5f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_obstruction = null;
|
||||
_cameraOffset = transform.position - _player.position;
|
||||
transform.LookAt(_player);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector3 newPosition = _player.position + _cameraOffset;
|
||||
|
||||
transform.position = Vector3.Slerp(transform.position, newPosition, _smoothFactor);
|
||||
ViewObstructed();
|
||||
}
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraPlayerFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private Transform _player;
|
||||
|
||||
private Vector3 _cameraOffset;
|
||||
|
||||
private Transform _obstruction;
|
||||
|
||||
[SerializeField]
|
||||
[Range(0.01f, 1.0f)]
|
||||
private float _smoothFactor = 0.5f;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
_obstruction = null;
|
||||
_cameraOffset = transform.position - _player.position;
|
||||
transform.LookAt(_player);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
Vector3 newPosition = _player.position + _cameraOffset;
|
||||
|
||||
transform.position = Vector3.Slerp(transform.position, newPosition, _smoothFactor);
|
||||
ViewObstructed();
|
||||
}
|
||||
|
||||
private void ViewObstructed()
|
||||
{
|
||||
RaycastHit hit;
|
||||
if (Physics.Raycast(transform.position, _player.position - transform.position, out hit, 1.5f))
|
||||
if (Physics.Raycast(transform.position, _player.position - transform.position, out hit, 3.5f))
|
||||
{
|
||||
if (hit.collider.gameObject.tag != "Player")
|
||||
{
|
||||
@@ -44,5 +44,5 @@ public class CameraPlayerFollow : MonoBehaviour
|
||||
_obstruction.gameObject.GetComponent<MeshRenderer>().shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.On;
|
||||
_obstruction = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user