#sorry
1 messages · Page 1 of 1 (latest)
whats up
U want to dup the purple thing
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.
OOH
ive said this many times
no
yes
Wdym no ?
so you have your object that's the sword, right?
No he wants to dupe that image
oh
.
i wasn't sure which part of that video sorry
So idkman
can you do something for me?
yes
this thread already has 30 messages dear lordf
now, can you drag that into the "assets" folder?
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
ok did it
do not mention Object pooling to this man
lol
please FlatHippo, that's too advanced for this situation. Baby steps.
We arent so far behind that idea rn
can you show me a picture of it in the assets folder?
its quite easy to follow a tutorial on youtube
haha
baby steps please
When hes ready
or download assets
hippo stop
im not trying to be mean
I am recommending the best course of action...
im sure u have good interntions now is just not the right time
I wouldn't teach someone the wrong way to multiply numbers the same way i wouldnt teach someone the wrong way to manage prefabs
i mean
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?
yes
no, but you'd teach people addition before you teach them multiplication.
remove the duplicator script.
remove the atak Component
u could just have said that
WE DID
NO
like this
if he can make a prefab that is the addition
do this on the object in the assets folder
removed
now press play
ok, now create a NEW game object in the scene.
no
it wont dupe now
yes, that's good.
keep listening to me idkman
can you create a new game object for me in the scene?
yes
now, to that empty game object can you add the dupe script?
insert the prefab (the one without the atk script) into the inspector for gameobjecttodup
I didn't see how far this convo goes back
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;
}
}
}```
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?
u mean this right
i would recommend watching beginner tutorials on youtube, it would go much faster than someone walking you through it on discord
yes
i did watch it
dont talk to him
k
no offense hes leading u off track
now can you show me a picture of the inspector of that new game object?
leading him off track? he's currently in Africa trying to ride his bike to Canada
ok, see that "Object To Duplicate" field? Can you drag the object from the assets folder into that field?
i did watch tutorials1!11
yes
just let them be, there's 2 people helping, what's the worst thing can happen?
the conversation has been going on for upwards of an hour, the worst has already happened
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.
just let Hero and IdkMan talk
U still with us idk?
that way this new object will be in the same position as the object you originally had the dupe script on.
ok so
makes sense to me
other object
its called a prefab
what other object
go to that, right click on the transform, and hit copy position like in the picture
the one in the scene
no its still here
ok, select that and do this
ok, now delete the red object in the scene then press play
?
NOT the one in the assets folder, because we want that one saved.
the one in the scene so yes
if that one had the dupe script on it originally, yea delete it
ok its gone
let's just see what happens when play is pressed.
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.
only one time, right?
yess
Did it work ?
okay, now we need to fix your code
okay
this is your code, right?
if (!hasBeenDuplicated)
{
Instantiate(objectToDuplicate, transform.position, transform.rotation);
hasBeenDuplicated = true;
}; someCooldown = Time.time + 3;
either im high or theres a extra semicolon
so, you created a prefab. That's an object that's saved as a file not in a scene.
i see
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.
okay
so, in your code can you create a private float?
yes
now above any if statement, but still inside the Update() function, I want you to do
theFloatYouJustMade += Time.deltaTime;
remove the second number += Time.deltaTime
okay
now, change that first if statement to be if number is greater than cooldown
close. You want number > someCooldown
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?
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(...)
can I see to make sure everything is correct so far?
ok. Two Three more things, okay?
okayy
first, line 9. make that variable public so you can edit it in the inspector.
ok, now for float number, can you set it equal to Mathf.Infinity?
so like
private float number = Mathf.Infinity;
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
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.
do you know why it works?
add comments to your code to explain it to yourself so you can look back later on.
its like
i understand most of it
okay
yes
i understand it now
took a look to code
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?
yes
ok, you're all set now.