#Phase > Pattern > Projectile

1 messages · Page 1 of 1 (latest)

still bane
#

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

south patrol
#

For/foreach loop is very basic, you should learn to use it right away

still bane
#

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

hexed quartz
#

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()

still bane
#

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

south patrol
#

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

still bane
#

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

south patrol
#

Sure, that would work

still bane
#

@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

south patrol
still bane
#

inside the pattern

south patrol
#

If you want a "dropdown" variable inside the pattern, just create an Enum

still bane
#

like this

#

idk how id do that though

south patrol
#
public enum PatternType
{
  Shotgun,
  Spray,
}```
#

Then inside the pattern class you would add a field of the type PatternType

#

Or a property

still bane
#

also idk if using scriptableobjects would be better

south patrol
#
// Field
public PatternType patternType;
// Or property
[Field: SerializeField] public PatternType patternType { get; private set; }```
still bane
#

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....

south patrol
#

Seems ok

#

It's up to you to have the logic (the method) in the struct or in the class itself

still bane
#

a problem does occour though

#

am I seriously gonna need a reference for the object that the script is on?

south patrol
#

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

south patrol
#

Ok and how does the struct know what transform is?

still bane
#

thing is itd require a lot of weird ass modifications for it to work

still bane
south patrol
#

The struct itself has no idea what gameobject's component it is on

still bane
#

yeah

south patrol
#

As I said, you need to pass the gameobject as a parameter to the Shotgun function, for example

still bane
#

ig I'll just pass a reference for the gameobject its on

#

holy fuck its so cool

south patrol
#

Yep

still bane
#

its also funny because I have a list of lists of 2 lists of parameters