#Phase > Pattern > Projectile
1 messages · Page 1 of 1 (latest)
so
I set the name to be the idea
one Phase script has a list of patterns
and each pattern has a set projectile
not a list of projectiles yet, im not getting too fancy
I'm not sure how I'd go about using for yet
its gonna be a bit more advanced than what im used to
but probably not that hard
@south patrol @tropic onyx
For/foreach loop is very basic, you should learn to use it right away
i know how to use them in general data management
but I've never had to use a for loop in a, say, Update() method before
where it gets ran every frame
I got the basics down with like c++ mathematical questions
and using them for object pooling also got me some practice
it'll loop until the end of the loop every time update() is called (every frame)
if you want to do something like "spawn a bullet, wait 0.1s, repeat 9x" then you're better off using a loop inside coroutine rather than Update()
yeah
I mean
its more like
I have 3 types of patterns
one fires projA, another fires projB and third fires projC
projA gets fired every second, projB gets fired every 2 seconds, and projC gets fired every 3 seconds
on second 1, only projA gets fired, but on second 2 I need to fire both projA and projB
so I essentially need to loop through every pattern every frame, check if their cooldown has expired, and if it did, fire them
I would add a float on those shot patterns that stores the last time it was fired
Then in update you would just check if enough time has passed since its last shot
If enough time passed, update its last shot time to current time and shoot
thats what i do so far
yeah
I was also thinking of like coroutines
but kind of recursive coroutines
where I tell the coroutine to fire a projectile in a certain way once after x seconds, and at the end just call itself to fire again after x seconds
But I never used coroutines before and I think the method that im currently using and you suggested might be better
Sure, that would work
@south patrol yeah ill just use this method
how can I create like a dropdown menu
like having a variable that can make it so it's either a shotgun pattern, a spray pattern or some other pattern
Inside the pattern itself, or in the component?
inside the pattern
If you want a "dropdown" variable inside the pattern, just create an Enum
public enum PatternType
{
Shotgun,
Spray,
}```
Then inside the pattern class you would add a field of the type PatternType
Or a property
also idk if using scriptableobjects would be better
// Field
public PatternType patternType;
// Or property
[Field: SerializeField] public PatternType patternType { get; private set; }```
probably not because i wont be switching between scenes
also hold on
its not what i wanted xd
ill just have 2 lists
one for shotguns and one for sprays
so
i want to loop through the list of shotgunpatterns
and do shit
oh god
I can have functions in structs
I can essentially have the function for firing the projectiles inside my struct
this is so unclean
but i think its better
I can just call shotgunPatterns[i].Shotgun() whenever shotgunPatterns[i].lifeTime >= 0f
is that fine?
oh, yeah
im also gonna need a list of phases later....
Seems ok
It's up to you to have the logic (the method) in the struct or in the class itself
uhhh
a problem does occour though
am I seriously gonna need a reference for the object that the script is on?
There you go. You need to either pass the transform/gameobject as a parameter to the struct, or just do the logic in the patternhandler script
I would probably just do it in the patternhandler
i do it in the struct itself
Ok and how does the struct know what transform is?
thing is itd require a lot of weird ass modifications for it to work
I wanted it to use the transform of the gameobject that its on
The struct itself has no idea what gameobject's component it is on
yeah
As I said, you need to pass the gameobject as a parameter to the Shotgun function, for example
ig I'll just pass a reference for the gameobject its on
holy fuck its so cool
this is some satisfying stuff after having to attach 9 of the same component on one gameobject
Yep
its also funny because I have a list of lists of 2 lists of parameters