Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
instantiate Spline Controller at runtime
#3
Ok Cross-checking that thread I did manage to figure this out.


For anyone in the future here is my code to make this work.

Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using FluffyUnderware.Curvy.Controllers;
using FluffyUnderware.Curvy;

public class VehicleSpawner : MonoBehaviour
{
   private SplineController sc;
   public GameObject[] vehicles;
   public float spawnInterval;
   public CurvySpline road;

   private void Start()
   {
       
       StartCoroutine(SpawnVehicles());
   }

   private IEnumerator SpawnVehicles()
   {
       while (true)
       {
           int index;
           index = Random.Range(0, vehicles.Length - 1);
           Instantiate(vehicles[index]);
           sc = vehicles[index].GetComponent<SplineController>();
           sc.Spline = road;
           yield return new WaitForSeconds(spawnInterval);
       }
   }
}

Hope it helps Smile
Reply


Messages In This Thread
RE: instantiate Spline Controller at runtime - by PretzelStudios - 05-07-2020, 09:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Set Volume to the Volume Controller at Runtime pako88 2 10 04-08-2024, 03:26 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_

Forum Jump: