#sorry

1 messages · Page 1 of 1 (latest)

rugged linden
#

ok so uh

pearl spruce
#

make a prefab

#

of the boss enemy

rugged linden
#

i alr got it

#

wait so

pearl spruce
#

whats up

rugged linden
#

this is thing i want to dupe

#

boss projectile

pearl spruce
#

U want to dup the purple thing

rugged linden
#

dupe this

drowsy reef
#

In summary:

If you duplicate the thing that has the duplicator on it, you will of course duplicate the duplicator which will then start duplicating itself, in an endless loop.

Just have a separate object that duplicates something else, not itself.

rugged linden
#

OOH

pearl spruce
#

ive said this many times

rugged linden
#

SO duplicate sprite and

#

other components becides script

drowsy reef
#

no

pearl spruce
#

yes

drowsy reef
#

no

#

no

pearl spruce
#

Wdym no ?

drowsy reef
#

so you have your object that's the sword, right?

pearl spruce
#

No he wants to dupe that image

drowsy reef
#

oh

rugged linden
pearl spruce
#

that red thing

drowsy reef
#

i wasn't sure which part of that video sorry

#

So idkman

#

can you do something for me?

rugged linden
#

yes

pearl spruce
#

this thread already has 30 messages dear lordf

drowsy reef
#

can you select that object in the Hierarchy?

#

so it's highlighted like this?

rugged linden
drowsy reef
#

now, can you drag that into the "assets" folder?

full epoch
#

if you are going to be using a lot of the same object I recommend object pooling. If you arent using that many, simply make a prefab, and then make instances of that prefab through a different object which has a script instantiating these prefabs

rugged linden
#

ok did it

pearl spruce
#

do not mention Object pooling to this man

astral sentinel
#

lol

drowsy reef
#

please FlatHippo, that's too advanced for this situation. Baby steps.

pearl spruce
#

We arent so far behind that idea rn

drowsy reef
full epoch
#

its quite easy to follow a tutorial on youtube

drowsy reef
#

baby steps please

pearl spruce
#

When hes ready

full epoch
#

or download assets

pearl spruce
#

hippo stop

rugged linden
pearl spruce
#

im not trying to be mean

full epoch
#

I am recommending the best course of action...

pearl spruce
#

im sure u have good interntions now is just not the right time

full epoch
#

I wouldn't teach someone the wrong way to multiply numbers the same way i wouldnt teach someone the wrong way to manage prefabs

drowsy reef
# rugged linden

ok, now select it. Do you see the right side of the inspector how it has all the same stuff as the one in the scene?

rugged linden
#

yes

drowsy reef
drowsy reef
pearl spruce
#

remove the atak Component

rugged linden
#

u could just have said that

pearl spruce
#

WE DID

rugged linden
#

NO

drowsy reef
#

like this

full epoch
#

if he can make a prefab that is the addition

drowsy reef
#

do this on the object in the assets folder

rugged linden
pearl spruce
#

now press play

drowsy reef
#

ok, now create a NEW game object in the scene.

drowsy reef
rugged linden
#

it wont dupe now

drowsy reef
#

yes, that's good.

#

keep listening to me idkman

#

can you create a new game object for me in the scene?

rugged linden
#

yes

drowsy reef
#

now, to that empty game object can you add the dupe script?

pearl spruce
#

insert the prefab (the one without the atk script) into the inspector for gameobjecttodup

full epoch
#

I didn't see how far this convo goes back

rugged linden
# drowsy reef now, to that empty game object can you add the dupe script?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class atak : MonoBehaviour
{
    public GameObject objectToDuplicate;
    private bool hasBeenDuplicated = false;
    float someCooldown;

    void Update()
    {
        if (Time.time > someCooldown)
        {
 
            if (!hasBeenDuplicated)
            {
                Instantiate(objectToDuplicate, transform.position, transform.rotation);
                hasBeenDuplicated = true;
            }; someCooldown = Time.time + 3;
        }

    }

}```
drowsy reef
# rugged linden yes

after you add the dupe script to that game object, can you send me a picture of the inspector with that verry same object selected?

rugged linden
#

u mean this right

full epoch
#

i would recommend watching beginner tutorials on youtube, it would go much faster than someone walking you through it on discord

drowsy reef
pearl spruce
#

dont talk to him

pearl spruce
#

no offense hes leading u off track

drowsy reef
#

now can you show me a picture of the inspector of that new game object?

rugged linden
full epoch
#

leading him off track? he's currently in Africa trying to ride his bike to Canada

drowsy reef
#

ok, see that "Object To Duplicate" field? Can you drag the object from the assets folder into that field?

pearl spruce
full epoch
drowsy reef
#

now, position that new game object to the same position of the other object in the scene. Just right click on the transform of the other object and hit copy, then paste it onto the new transform of the new object.

pearl spruce
#

just let Hero and IdkMan talk

drowsy reef
pearl spruce
#

U still with us idk?

drowsy reef
#

that way this new object will be in the same position as the object you originally had the dupe script on.

rugged linden
#

ok so

pearl spruce
#

makes sense to me

rugged linden
#

other object

pearl spruce
#

its called a prefab

rugged linden
#

what other object

drowsy reef
#

so

#

you know how you were trying to duplicate that red thing?

#

that object

rugged linden
#

yes

#

ok

drowsy reef
#

go to that, right click on the transform, and hit copy position like in the picture

#

the one in the scene

rugged linden
#

and

#

new object is one in scene

#

right

drowsy reef
#

did you delete the old red object that was in the scene?

#

it's fine if you did

rugged linden
#

no its still here

drowsy reef
rugged linden
#

i did that

#

after that what

drowsy reef
#

you got it?

rugged linden
#

i did it

#

yes

drowsy reef
#

ok, now delete the red object in the scene then press play

pearl spruce
#

?

drowsy reef
#

NOT the one in the assets folder, because we want that one saved.

rugged linden
#

i know that much

#

this one right

pearl spruce
#

the one in the scene so yes

drowsy reef
#

if that one had the dupe script on it originally, yea delete it

rugged linden
#

ok its gone

pearl spruce
#

press play

#

i dont think this is gonna work

drowsy reef
#

let's just see what happens when play is pressed.

rugged linden
#

i think he is gonna give more steps

#

okay

pearl spruce
#

Just try it

#

if it works it works who cares what i think

drowsy reef
#

I believe it will only duplicate it one time, but we're on the right track if that's the case. But if it works as expected then great.

rugged linden
drowsy reef
#

only one time, right?

rugged linden
#

yess

pearl spruce
#

Did it work ?

drowsy reef
#

okay, now we need to fix your code

rugged linden
#

okay

rugged linden
#

before that

#

can you explain what you made me do

pearl spruce
#

if (!hasBeenDuplicated)
{
Instantiate(objectToDuplicate, transform.position, transform.rotation);
hasBeenDuplicated = true;
}; someCooldown = Time.time + 3;

#

either im high or theres a extra semicolon

drowsy reef
rugged linden
#

i see

drowsy reef
#

I had you remove the duplicator script from the object you're duplicating because if it duplicates the object with the duplicator, then the duplicator will trigger again.

#

so you moved the duplicator to a new game object that won't copy itself.

rugged linden
#

okay

drowsy reef
#

so, in your code can you create a private float?

rugged linden
#

yes

drowsy reef
#

now above any if statement, but still inside the Update() function, I want you to do

theFloatYouJustMade += Time.deltaTime;
rugged linden
#

this right

drowsy reef
#

remove the second number += Time.deltaTime

rugged linden
#

okay

drowsy reef
#

now, change that first if statement to be if number is greater than cooldown

rugged linden
#

this right

drowsy reef
#

close. You want number > someCooldown

rugged linden
#

oh my bad

#

ok i did that

drowsy reef
#

because Time.dletaTime will always be a small number, because it's just the time between frames. So you're adding it to the number variable to make it larger and larger to count time. Make sense?

rugged linden
#

i see

#

yes

drowsy reef
#

ok, now delete everything inside the first if statement except the call to the Instantiate method.

#

so the only thing you'd have inside of if(number > someCooldown is Instantiate(...)

rugged linden
#

okay

#

i did it

drowsy reef
#

can I see to make sure everything is correct so far?

rugged linden
drowsy reef
#

ok. Two Three more things, okay?

rugged linden
#

okayy

drowsy reef
#

first, line 9. make that variable public so you can edit it in the inspector.

rugged linden
#

yes

#

i did that

drowsy reef
#

ok, now for float number, can you set it equal to Mathf.Infinity?

#

so like

private float number = Mathf.Infinity;
rugged linden
#

that is making this go for infinity?

#

yes i did that

drowsy reef
#

no. That's just making sure the number will always be bigger than the cooldown so it spawns it instantly the first time without waiting for the cooldown first

rugged linden
#

oooh

#

okay

drowsy reef
#

last thing

#

in the if statement

#

after the instantiate line

#

do number = 0;

rugged linden
#

okay

#

should i test it now

drowsy reef
#

that way it resets the count after it spawns it.

#

yes

rugged linden
drowsy reef
#

don't forget to set the cooldown in the inspector! It defaults to 0.

#

so if you want 3 seconds, put 3 as the cooldown.

rugged linden
#

okay

#

YES

#

IT WORKS!!!

drowsy reef
#

do you know why it works?

#

add comments to your code to explain it to yourself so you can look back later on.

rugged linden
#

its like

#

i understand most of it

#

okay

#

yes

#

i understand it now

#

took a look to code

drowsy reef
#

first we add Time.deltaTime, the time between frames, to a number. That keeps track of time.

Then we compare it to the cooldown to see if that time is greater than the cooldown.

If it is, we instantiate the object.
Then we set the time to 0, because if we left it alone it would be greater than the cooldown again next frame, right?

rugged linden
#

yes

drowsy reef
#

ok, you're all set now.

rugged linden
#

thanks again

#

with ur level for helping me