#Cube Enemy Script Help

1 messages Β· Page 1 of 1 (latest)

cyan rose
#

.

amber ferry
#

okay why don't you describe your issue with detail so everyone is on the same page

cyan rose
#

No issue yet, was just told to make a thread. There will be a lot of issues though...

amber ferry
#

that's very positive thinking lol

cyan rose
#

And I can't figure out how to get the distance between two Vector3s. I just can't find it.

random raven
#

Really? The function is literally called Vector3.Distance, it has got to be the first result in any sensible search

cyan rose
#

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

worldly yoke
#

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

warped summit
#

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

kindred jettyBOT
#

πŸ§‘β€πŸ« 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/

cyan rose
#

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

random raven
worldly yoke
random raven
#

You expose the field in the class scope, and access it anywhere inside of a method

cyan rose
#

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

#

ah

#

still learning about coroutines

#

How do layer masks work?

#

If it's a checklist, how can it be represented with a single int?

cyan rose
#

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.

random raven
#

You can with the right formatting (0b00000000000000100000000000000000), but why you would...

cyan rose
#

So I'm only getting the bool value from this. How do I get the second RaycastHit from it?

random raven
#

look at the overloads, either using the !api or look via your IDE's suggestions

kindred jettyBOT
cyan rose
random raven
cyan rose
#

Not at my PC rn but last night I tried that and it didn't work, even though everything seemed to be correct.

cyan rose
#

Nvm

cyan rose
#

But I figured out the problem

#

The out in the example was in parentheses

#

Oh wait you already said that lol

cyan rose
#
    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

cyan rose
#

I forgot to tell it what the player was πŸ˜…

cyan rose
#

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

cyan rose
#

ah

cyan rose
#

It works! Now to figure out the cooldown