I need to know if is possible apply this change:
I have a driving simulator build using Unity. In a scene, there are some evets that leave when the player car passes through waypoints. Now this waypoints are in fixed position, the player car run some meters and when it passes through the waypont the event is triggered and started. Now I need to change this and I want that the player car can be run for some minutes before passes through the waypoint but this time should be managed from backend code.
In the follow image, you can display one of my waypoint

I had hypothesized if it was possible to lengthen the pieces of road but from the code, but I have no idea how and if it can be done. For the road I used this component EasyRoad
EDIT This is a RoadCrossEventTrigger, this class is called when the car pass into a waypoint.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace DrivingTest
{
public class RoadCrossEventTrigger : MonoBehaviour
{
// Inspector variables
[SerializeField] private float characterSpeed;
[SerializeField] private float timeActive;
[SerializeField] private float factor;
[SerializeField] private GameObject roadCrossCharacter;
[SerializeField] private eCharacterType characterType;
// Private variables
private bool eventNotHappened = true;
public static eComplexity? testComplexity;
// Public variables
public static System.Action<eCharacterType> characterRoadCrossEvent;
/// <summary>
/// These triggers are placed a certain distance before the different events(kid/ dog/ bus man).
/// Whenever the player's car interacts with the trigger. The trigger starts a coroutine that executes the event.
/// </summary>
private void OnTriggerEnter(Collider other)
{
if(testComplexity != null && (testComplexity == eComplexity.Low || testComplexity == eComplexity.Medium))
{
//non devono partire eventi. Quindi no il bambino, no il cane, no la persona che scende dal bus.
}else if (testComplexity != null && testComplexity == eComplexity.High)
{
//devono partire eventi. Quindi il bambino, il cane, la persona che scende dal bus nel test TDF
eventNotHappened = false;
//Determines the time taken by the Player's car to reach the lane car after entering the trigger.
float timeToReach = Vector3.Magnitude(other.transform.position - roadCrossCharacter.transform.position) / other.gameObject.GetComponent<IRDSCarControllInput>().CarSpeed;
timeToReach *= factor;
StartCoroutine(SpawnCharacter(timeToReach));
}
else if (other.tag == Constants.PLAYER_TAG && eventNotHappened)
{
// Makes sure that the trigger fires the coroutine only the first time.
eventNotHappened = false;
//Determines the time taken by the Player's car to reach the lane car after entering the trigger.
float timeToReach = Vector3.Magnitude(other.transform.position - roadCrossCharacter.transform.position) / other.gameObject.GetComponent<IRDSCarControllInput>().CarSpeed;
timeToReach *= factor;
StartCoroutine(SpawnCharacter(timeToReach));
}
}
/// <summary>
/// Invokes the event that tells the CLNC class that the event has begun.
/// Moves the event character(kid/ dog/ bus man)
/// </summary>
/// <param name="time"> The time for which the coroutine waits before executing.</param>
IEnumerator SpawnCharacter(float time)
{
yield return new WaitForSeconds(time);
characterRoadCrossEvent?.Invoke(characterType);
if (roadCrossCharacter != null)
{
roadCrossCharacter.SetActive(true);
}
else
{
Debug.LogError("Road crossing character's reference is missing!!");
yield break;
}
float t = 0;
while (t < timeActive)
{
roadCrossCharacter.transform.Translate(Vector3.forward * characterSpeed * Time.deltaTime * 10);
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
roadCrossCharacter.SetActive(false);
}
}
}
In SpwnCharaceter method if I insert this vlaue (60) the event start after 60 second, but after 60 seconds the user's car has already passed through the point where my event is located and therefore is not displayed.
Currently in point X there is the waypoint, on the road after a few meters my GameObject is positioned such as a child running in the middle of the road. Child waypoint distance is currently fixed. I would like to be able to manage it from code, I don't know if it is therefore possible to dynamically extend the road between the waypoint and the child.
