//----------------------------------------------
// 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;
///
/// Trailer attacher point. Trailer will be attached when two trigger colliders triggers each other.
///
[AddComponentMenu("BoneCracker Games/Realistic Car Controller/Misc/RCC Trailer Attacher")]
public class RCC_TrailerAttachPoint : MonoBehaviour {
private void OnTriggerEnter(Collider col) {
// Getting other attacher.
RCC_TrailerAttachPoint otherAttacher = col.gameObject.GetComponent();
// If no attacher found, return.
if (!otherAttacher)
return;
// Other vehicle.
RCC_CarControllerV3 otherVehicle = otherAttacher.gameObject.GetComponentInParent();
// If no vehicle found, return.
if (!otherVehicle)
return;
// Attach the trailer.
GetComponentInParent().transform.SendMessage("AttachTrailer", otherVehicle, SendMessageOptions.DontRequireReceiver);
}
private void Reset() {
if (GetComponent() == null)
gameObject.AddComponent().isTrigger = true;
}
}