//----------------------------------------------
// Realistic Car Controller
//
// Copyright © 2014 - 2023 BoneCracker Games
// https://www.bonecrackergames.com
// Buğra Özdoğanlar
//
//----------------------------------------------
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
///
/// RCC Camera will be parented to this gameobject when current camera mode is Hood Camera.
///
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/Camera/RCC Hood Camera")]
public class RCC_HoodCamera : MonoBehaviour {
private void Awake() {
CheckJoint();
}
///
/// Fixing shake bug of the rigid.
///
public void FixShake() {
StartCoroutine(FixShakeDelayed());
}
IEnumerator FixShakeDelayed() {
// If no rigid found, return.
if (!GetComponent())
yield break;
yield return new WaitForFixedUpdate();
GetComponent().interpolation = RigidbodyInterpolation.None;
yield return new WaitForFixedUpdate();
GetComponent().interpolation = RigidbodyInterpolation.Interpolate;
}
///
/// Checking configurable joint.
///
private void CheckJoint() {
// Getting configurable joint.
ConfigurableJoint joint = GetComponent();
// If no joint found, return.
if (!joint)
return;
// If connected body of the joint is null, set it to car controller itself.
if (joint.connectedBody == null) {
RCC_CarControllerV3 carController = GetComponentInParent();
if (carController) {
joint.connectedBody = carController.GetComponent();
} else {
Debug.LogError("Hood camera of the " + transform.root.name + " has configurable joint with no connected body! Disabling rigid and joint of the camera.");
Destroy(joint);
Rigidbody rigid = GetComponent();
if (rigid)
Destroy(rigid);
}
}
}
private void Reset() {
ConfigurableJoint joint = GetComponent();
if (!joint)
return;
RCC_CarControllerV3 carController = GetComponentInParent();
if (!carController)
return;
joint.connectedBody = carController.GetComponent();
joint.connectedMassScale = 0f;
}
}