Home>

When approaching an enemy vehicle using Unity's StandardAsset<Vehicles<Car<Prefabs<Car
I would like to implement a function to stop before slowing down and hitting
I can get information on enemy vehicles with RayCast, but I don't know how to apply the brakes with my own script.

It seems that you can play with Move in CarController.cs in StandardAseet ...
I don't know where to go from there.

nearTest.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.Vehicles.Car;

public class nearTest: MonoBehaviour {
    private CarController _carController;
    private RayCast _raycast;
    void Start ()
    {
        _carController = GetComponent&lt;CarController&gt;();
        _raycast = GetComponent&lt;RayCast&gt;();
    }
    void FixedUpdate ()
    {
        // Get own vehicle speed
        float currentSpeed ​​= _carController.CurrentSpeed;
        // brake if Ray hits an enemy car
        if (_raycast.hittingFront) {
            // I don't know here
            Debug.Log ("Apply the brake");

        }
    }
}

`` `