Need help with scenery.

Hey guys I am trying to make add some scenery to each side of the road as it moves but I’m not sure how to implement it, I downloaded the terrain assets , but I couldn’t find grass so help with how I would make the scenery (preferably random and allow it to move with the road would be appreciated).

I imagine I could bunch all the plants and grass and stuff together as one object and then spawn them on the side of the road? Only thing is I don’t want the player to see the same scenery every time he plays so how would I make the scenery random as well?

I haven’t done this before, but if that camera view is pretty much going to stay about like it is (can’t turn around and look behind you, for example), my first thought would be to spawn a bunch of game objects as plants and whatever in the beginning. As they move out of view behind the camera while you’re moving down the road, just randomly reposition them out front somewhere.

You could probably do that with the road too, just swap tiles from behind the cam to the front. Your whole world would be very small then, but if the camera is restricted appropriately you’d be the only one who knew that. :wink:

Ha , Yeah. I used a queue for the road , so the road is fine , I tried using the script for the road on a fence and a plant but it seems the script should only be used for the road. And the camera isn’t moving , it is in one position as is the player . The only thing that is moving is the road.

Tried the script on a bamboo plant , spawned way too much of them.And as you can see are way too big.

Here is the script that I used for the road that won’t work on anything else .Think you could help me modify it a bit?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RoadController : MonoBehaviour
{
    public GameObject roadPrefab;
 
    protected const int roadSegments = 46;
    protected Queue<Transform> road;
 
    protected void Start()
    {
        road = new Queue<Transform>();
     
        // generate the road
        for(int i = -5; i < roadSegments - 5; ++i)
        {
            // make a new "strip" of the road
            GameObject segment;

                segment = Instantiate<GameObject>(roadPrefab);

            // position it
            segment.transform.position = new Vector3(0.0f, 0.0f, i);
         
            // put it in the queue
            road.Enqueue(segment.transform);
        }
    }
 
    protected void Update()
    {
        // move the road
        foreach (Transform segment in road)
            segment.position -= Vector3.forward * 2.0f * Time.deltaTime;
     
        // check to see if we have to move the first segment
        if(road.Peek().position.z <= -5)
        {
            // move it to the end of the line
            Transform movingSegment = road.Dequeue();
         
            movingSegment.position += Vector3.forward * roadSegments;
         
            // re-queue it
            road.Enqueue(movingSegment);
        }
    }
}

Tell me if anyone needs a better explanation to help me out!

It might be time to get a programming book.

Sorry, but it looks to me like you’re just putting a game together by copy/pasting scripts other people have written. You won’t get very far that way.

1 Like

Or maybe look into a visual scripting tool like PlayMaker. Great investment if you unable to code - like me.

You’re right. I have mostly just been asking for code instead of writing it myself. Any resources you can give me to help me learn proper C# code so I can finish the game on my own? Or is the Unity tuts enough? Thanks for bringing a problem I should’ve confronted a while ago to my face. Thanks!

We were all beginners at some point! Everything here is really useful! Here is another Unity-official tutorial set. Those and the docs will cover everything you will ever need to know to start. Most basic questions can be solved with Google~ More advanced questions can be handled right here on the forums!

Thanks for understanding! but one question. Do you think by using the resources you gave me I will be able to finish this project or should I work on an easier game?

Some people do well with video tuts and so on. Some people (like me) do much better with books instead. I’ve got one C# book which has taught me about everything I need to know about the language:

“Microsoft Visual C# 2012” (of course you might want a newer version). It’s centered around Visual Studio, but if you don’t have that it’s ok. It still teaches the ins and outs of programming in C# and you can apply it to Unity.

Hmm ok, I know this is subjective but do you think someone like me who does better with tuts instead of books ( Although I don’t mind coding books if I HAVE to red them )could go through the unity tuts on the site and finish a sort of complex endless runner game that I showed at the start of the thread? I’m kind of basing the game off of another endless runner called Traffic Racer. Do you think I could make something like that at my level of coding? I’ve already accomplished a lot so I don’t wanna give up on it.

Sure. It seems a lot of people do just fine with tutorials. :slight_smile:

Thanks for all the help. But I have one problem. I have went through the unity tuts before and I can’t seem to apply any of the code I learn. Can you please help me to be able to use the coding resources I was given and learn how to actually apply them to like for example randomly spawn scenery ? Basically I’m saying that after I go through the resources to help me learn C# how do I apply what I have learned?

This is probably as good a place to start as any: Unity Learn

I may be coming at this a little differently from people today. I learned to program first, then started writing games. It seems a lot of people are trying to come at it from the other direction. Some folks do seem to have some success with that, but I just can’t really imagine making a game without writing any code. So I can’t really help you beyond that other than to say “look at the tutorials.” Sorry.