#Code problem random.range

1 messages · Page 1 of 1 (latest)

broken currentBOT
#

An image of your code is not helpful

When asking a question about a problem with code, people who are volunteering to help need the text of the code. Unless you are asking about your IDE - and not the code itself - images of the code are not an acceptable substitute.
Source: https://idownvotedbecau.se/imageofcode

Please send your code as a codeblock. If you don't know how to send a codeblock, type []cb

shrewd apex
#

I don't know how you expect anyone to be able to read that

queen crescent
#

public GameObject pipe;
public float spwanrate= 3;
private float timer = 0;
public float heightOffset = 10;
// Start is called before the first frame update
void Start()
{

    spwanpipe();
}

// Update is called once per frame
void Update()
{
    if (timer < spwanrate)
    {
        timer = timer + Time.deltaTime;
    

    }
    else
    {
        spwanpipe();

        timer = 0;
    }

    
}
void spwanpipe()
{
    float lowestPoint = transform.position.y - heightOffset;
    float highestPoint = transform.position.y + heightOffset;

    Instantiate(pipe, new Vector3(transform.position.x, Random.rang(lowestPoint, highestPoint), 0), transform.position);
}

}

pulsar seal
#

Well first problem is Unity's random engine

#

Please use codeblocks

#

[]cb

broken currentBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

pulsar seal
#

Not that mobile supports highlighting yet

#

Also line 1 is the issue

#

You have no class

shrewd apex
#

Even at shitty potato resolution

#

you can see the class

pulsar seal
#

Look at the posted code kekw

shrewd apex
#

Well at any rate

shrewd apex
#

You're just throwing random code together hoping it works

#

First of all, you're passing an entire vector as the z parameter, why?

#

Second of all, what is rang?

queen crescent
shrewd apex
#

Right, so why did you hope that rang would work

#

also, PascalCase

golden spade
#

Also, this is from a tutorial online, I know it and made it. You inputted

  rang

Instead of

Random.Range()
queen crescent
#

I modified it, but there is a problem

golden spade
#

See that tutorial you had followed from, the words are exactly same as the tutorial

queen crescent
shrewd apex
queen crescent
#

It's the first game I programmed, and I was imitating the video exactly, but I don't know what the problem is here

shrewd apex
#

Hence why I asked what errors you are facing

#

We're not mind readers. We can't tell you what the problem is, that's your job. We're here to help you find a solution to the problem

queen crescent
#

I don't know where exactly the problem is, I did everything but to no avail

golden spade
#

That's strange, it worked exactly fine for me, once recheck the video

#

Also, what unity version are you using

queen crescent
#

@golden spade 2021

#

Please, can you photograph and send the codes that you wrote so that it works for you

rain gulch
rain gulch
#

Best way for me to put it is this: If you want us to help you, just tell what you want your game to do, and then tell us what your game actually does instead. Like for a very unrelated example, say your problem was with the audio. You could say something like "I want my music to play when I enter a new room, but all I hear is static."

#

If you already told us this, I can't see it. You deleted your original message.

shrewd apex
#

Their original message was just a really low-quality image of their code

#

So you are not missing anything

#

OP just has not explained their problem

queen crescent
#

I apologize guys, I won't bother you with these beginner questions againHmmmmStare
I enjoyed with you
goodbyecomfy

golden spade
#

Wait, on code why is

Quaternion.Identity

Replaced with

transform.position
#

Yep, that might be the problem

#

@queen crescent I don't know if it's serious or not,
But (for later of anyone's games)

Random.Range()

Some times gets an error where it says cannot convert UnityEngine.Vector3.
Unity thinks we're inputting a single float, not the 3 floats. The way to fix this that I saw on yt, is to create a new vector3
Var and assign the random.range in that.
For example,

void Update() {
    Vector3 c = new Vector3(transform.position.x, Random.Range(low, high), transform.position.z)

}

shrewd apex
#

That's an extremely inefficient way of doing it

golden spade
#

@shrewd apex but I works for me, and several other people uses it.

pulsar seal
#

Just because it works doesn't mean you should do it

#

You can use a knife to hammer in nails

halcyon lynx
#

but my friends use knives to hammer nails so it must be right!

mellow lagoon
#

Just close this post bruh 😭💀

lyric sluice
shrewd apex
#

We are still beginner friendly

#

But when OP refuses to give details on their problem, how the hell are we to help? blaze

uncut wave
#

funny thread