#Cube Enemy Script Help
1 messages Β· Page 1 of 1 (latest)
okay why don't you describe your issue with detail so everyone is on the same page
No issue yet, was just told to make a thread. There will be a lot of issues though...
that's very positive thinking lol
And I can't figure out how to get the distance between two Vector3s. I just can't find it.
Really? The function is literally called Vector3.Distance, it has got to be the first result in any sensible search
Just found it right before you said that. I thought it was the Visual Scripting one π
How do I save this to a variable? (Ignore my poor choice in font, please.)
Thanks
Keep in mind if you do float distance = inside Update, you'll only be able to use it in Update
if you want to use it outside of Update, you'll want to declare it outside, like this(roughly)
public class MyScript:MonoBehaviour
{
float distance;
void Update()
{
distance = Vector3.Distance(.....);
}
}
this concept is called scope. and the difference between class variables and local variables
@cyan rose These are the things that are covered by basic courses on !learn You are expected to know language basics to be able to understand the help you are given as well.
π§βπ« Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/
This feels stupid. Do I really have to do all this just to play a single animation?
Oh
But still
Uh, I didn't understand...
https://unity.huh.how/programming/references/serializing-component-references is the best way of doing it imo
same thing as what I said about declaring variables inside the function. you can only use animator inside Start if you declare it like that
You expose the field in the class scope, and access it anywhere inside of a method
I hate myself
Of course
now that horrible error is back
i have no idea what not all code paths return a value means
im not trying to give anything any values
what
ah
still learning about coroutines
How do layer masks work?
If it's a checklist, how can it be represented with a single int?
https://unity.huh.how/programming/physics/bitmasks
An integer has 32 bits, each bit is a checkmark
Why isn't it working?
Alright
Only 20 layers. (Forgot what ppvm is lol.)
Oh wait it was post processing viewmodel. That didn't work.
You can with the right formatting (0b00000000000000100000000000000000), but why you would...
So I'm only getting the bool value from this. How do I get the second RaycastHit from it?
look at the overloads, either using the !api or look via your IDE's suggestions
π» Learn in detail about the scripting API that Unity provides https://docs.unity3d.com/ScriptReference/
I'm... not sure what that means -_-" I know what the "outputs" are but I'm not sure how to access any except for the first.
There are examples in the documentation if you are confused
Not at my PC rn but last night I tried that and it didn't work, even though everything seemed to be correct.
The example was kinda hard to follow
But I figured out the problem
The out in the example was in parentheses
Oh wait you already said that lol
public QueryTriggerInteraction CollidesWithTriggers;
IEnumerator ShootAtPlayer()
{
yield return new WaitForSeconds(0.3f);
RaycastHit Raycast;
Physics.Raycast(this.transform.position, this.transform.forward, 10f, LMask, CollidesWithTriggers, out Raycast);
its acting really weird
with CollidesWithTriggers its like everything gets mixed up and has to be in a different order
without it its fine
it is according to the Physics.Raycast definition
why
i hate this
why does it just work until you put a single value in that it asked for and now HeY yOu NeEd To PuT eVeRyThInG iN a CoMpLeTeLy DiFfErEnT oRdEr ThAn I tOlD yOu To
How do I define a bool with another bool?
That fixed it π
Also I know this is basic but how do I write and? & didn't work and neither did the word.
Alright
π
i really am bad at coding
random.range
goddamnit
wow i did it
bool HitPlayer = Raycast.collider.gameObject.layer == 3 && Random.Range(1, 10) < 5;
k
I think this was an error on my part but here's how the first test went
I forgot to tell it what the player was π
Good start ig
I'm getting a null reference exception?
Debug.Log("Waiting");
yield return new WaitForSeconds(0.3f);
Debug.Log("Waited");
RaycastHit Raycast;
Physics.Raycast(this.transform.position, Gun.transform.up, out Raycast, 10f, LMask, CollidesWithTriggers);
if (Enabled)
{
bool HitPlayer = Raycast.collider.gameObject.layer == 3 && Random.Range(1, 11) < 5;
if (HitPlayer)
{
Debug.Log("Player Hit");
On the bool HitPlayer = Raycast.collider.gameObject.layer == 3 && Random.Range(1, 11) < 5;
You able to help? @thick aspen
ah