I just need my car that follows way-points to go 0 to 30 in “x” amount of seconds after its ray shows a false hit. I’m trying to understand mathf functions but everything I try isn’t working. Please help. Thanks!
using UnityEngine;
using System.Collections;
public class rayCast_car2 : MonoBehaviour
{
public GameObject car_1;
public float distanceToSee = 6f;
private bool targetHit;
private civic2MoveOnPath script;
void Start()
{
script = car_1.GetComponent<civic2MoveOnPath>();
}
void Update()
{
RaycastHit hit;
Ray slowDown = new Ray(transform.position, transform.forward * distanceToSee);
Debug.DrawRay(transform.position, transform.forward * distanceToSee, Color.magenta);
{
if (Physics.Raycast(slowDown, out hit, distanceToSee))
{
if (hit.collider.name == "Body Collider" && !targetHit)
{
Debug.Log("hit");
targetHit = true;
script.speed = 0f;
}
}
else if (targetHit)
{
Debug.Log("Not Hit");
targetHit = false;
script.speed = 30f;
}
}
}
}