Search Unity

Endless Car Running

Discussion in 'General Discussion' started by FearL0rd, Apr 6, 2021.

  1. FearL0rd

    FearL0rd

    Joined:
    Jul 26, 2018
    Posts:
    3
    I'm trying to create a endless running game but Im having few issues.

    I have a list of reads and what Im trying to do is delete de road from the list and add again with a delta in Z.
    I can see it "moved" because when I click I see it highlighted in the new position. what happens I never see the object draw at location.

    do you have an idea what happening?

     
  2. BenniKo

    BenniKo

    Joined:
    Mar 24, 2015
    Posts:
    100
    It's really hard to tell what is going on without the actual code.
    Please post that.
     
    FearL0rd, Socrates and Joe-Censored like this.
  3. FearL0rd

    FearL0rd

    Joined:
    Jul 26, 2018
    Posts:
    3
    My bad. Im attaching the code.

    Every time the player collides with a trigger it runs. I can debug the code and the trigger is working.


    This is the road spawner code

    Code (CSharp):
    1. public class RoadSpawner : MonoBehaviour
    2. {
    3.     // Start is called before the first frame update
    4.     public List<GameObject> roads;
    5.     private float offset = 22f;
    6.     void Start()
    7.     {
    8.         if (roads != null && roads.Count > 0)
    9.         {
    10.             roads = roads.OrderBy(r => r.transform.position.z).ToList();
    11.         }
    12.     }
    13.     public void MoveRoad()
    14.     {
    15.         GameObject moveroad = roads[0];
    16.         roads.Remove(moveroad);
    17.         float newZ = roads[roads.Count - 1].transform.position.z + offset;
    18.         moveroad.transform.position = new Vector3(0, 0, newZ);
    19.         roads.Add(moveroad);
    20.      }
    21.     void Update()
    22.     {
    23.     }
    24. }

    SpawnManager

    Code (CSharp):
    1.  
    2. public class SpawnManager : MonoBehaviour
    3. {
    4.     // Start is called before the first frame update
    5.     RoadSpawner roadspawner;
    6.     void Start()
    7.     {
    8.         roadspawner = GetComponent<RoadSpawner>();
    9.     }
    10.     // Update is called once per frame
    11.     void Update()
    12.     {
    13.      
    14.     }
    15.     public void SpawnTriggerEntered()
    16.     {
    17.         roadspawner.MoveRoad();
    18.     }
    19. }
     
  4. FearL0rd

    FearL0rd

    Joined:
    Jul 26, 2018
    Posts:
    3
    BTW I closed and Opened unity and it is working now :)
     
    BenniKo likes this.