❔ Trying to shorten this code.
The code works well, but it's a bit dual coded so I've been trying to shorten it. I can't find a good fix, though.
10 Replies
Then create a LayerMask object and determine whether or not it's 3D or 2D.
Then you'd have to do some logic based on if it's 3D or 2D.
And so on.
Is there a common type betwen the 2D and 3D masks?
I'm not fluent in Unity
But there's quite a bit that can be done to reduce redundancies here.
The only issue I have mentally is that I don't know if the raycast logic can be simplified to a single method through a common type
Starting with something like that
There other simplifications:
These aren't exact
Rather examples you can guide yourself with 🙂
@Tycho did you try asking Bing AI to do that for you?
I'm basically making a game that includes both 2D and 3D enemies, and then you have a 2D and 3D gun to shoot the respective enemy
If that makes sense
This is what I based my thing on.
Try to divide methods into smaller methods.
Makes it easier to read.
Is it a native type or something the OP would have to create on their own?
Native to Unity I think.
It says LayerMask, so I just assumed that it was a common type.
Yeah I was planning on refactoring when the entire game was done
Yes, LayerMask is a Unity component
Okay.
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.