PLEASE help

every time it said .the default value is 0 not assigned ,i am becoming stupid

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class monkeyjump : MonoBehaviour
{
    [SerializeField]
    private LayerMask platformsLayerMask;
    private Rigidbody2D rigidbody2d;
    private BoxCollider2D boxCollider2d;
    // Start is called before the first frame update
   private void Awake()
    {
        rigidbody2d = transform.GetComponent<Rigidbody2D>();
        boxCollider2d =  transform.GetComponent<BoxCollider2D>();
    }

    // Update is called once per frame
    private  void Update()
    {
        if (IsGrounded() && Input.GetKeyDown(KeyCode.Space)){
        float jumpVelocity = 35f;
        rigidbody2d.velocity = Vector2.up * jumpVelocity;
    }
}
    private bool IsGrounded() {
    RaycastHit2D raycastHit2d =    Physics2D.BoxCast(boxCollider2d.bounds.center, boxCollider2d.bounds.size, 0f, Vector2.down * .1f, platformsLayerMask);
    Debug.Log(raycastHit2d.collider);
    return raycastHit2d.collider != null;
    }
}

Post a more meaningful title then “Please Help”

Clearly state what you need help with, though my guess is it’s something with your platformsLayerMask.

1 Like

yes

Yes?

Still haven’t said what your issue is. Do you have a value assigned to your platformsLayerMask? I really have no clue how to help you and I’m guessing others aren’t either because you haven’t said what your issue is.

Field ‘monkeyjump.platformsLayerMask’ is never assigned to, and will always have its default value( Do you have a value assigned to your platformsLayerMask? ) what value ?i called the layer platform

So, the message is pretty clear. You have no value assigned to platformsLayerMask, so it is just using a default value, whatever that value might be.

Basically it’s just telling you that your code doesn’t have a line like
platformsLayerMask = some Value;

So it will always be using the default value.

1 Like

the value that i will insert depends from what? and how insert it (can you correct my code??

It’s whatever value you need for your Boxcast. So just set it equal to whatever you’re needing it to be. Can’t really correct your code as I don’t know what value you want there.

make me an example ,value 1 2 3 and effects

help

@michele2000bon_1 please edit your thread title as already asked by other member and do not create duplicates.

Please get familiar with doc
Physics2D.BoxCast

Then you need read about layer and layer mask. You of course may want to search for examples on the net.

The easiest thing to do is make your LayerMask public and then Unity will create a nice little inspector widget where you can select whatever layers you want.

can you correct my code???

Yes

1 Like

can you do it?

You added platformsLayerMask to the script for a reason. Whatever that reason was will dictate what value you should be setting it to. If you don’t know, then why did you add platformsLayerMask to this script at all?