I have a layermask set to just ignore the Player, the player is in the Player Layer(boy this is a tongue twister) anyway here is my code Code (CSharp): RaycastHit2D hit = Physics2D.Raycast(position, Vector2.up,RayLength, ignorePlayer); { Debug.Log("You have hit: " + hit.collider.name); } the ignorePlayer is the Layermask and the Debug is saying hit Player
This is what it looks like this is my first time using layermasks but I think that you are supposed to select the layer you want ignored from the drop down (if not please tell me).
Nope, do a: Code (CSharp): LayerMask ignorePlayer = ~(1 << ignorePlayer); This will basically invert the layerMask
ok so is the 1 mean the first layer or the number of layers that are masked and is << ignorePlayer the Layer name?
thanks but the 1 problem is is that i get this error error CS0236: A field initializer cannot reference the nonstatic field, method, or property and if I change it to static the error goes away but the layermask does not work
OK so here is my updated script: Code (CSharp): using UnityEngine; using System.Collections; public class Interaction_base : MonoBehaviour { public PlayerMovement playermovement; public float RayLength = Mathf.Sqrt(2);//How far the raycast will go Rigidbody2D player; void Start() { player = GetComponent<Rigidbody2D>(); } void Update() { Debug.DrawLine(player.position, player.position + playermovement.Direction * RayLength, Color.red); // Shows where the raycast is in the inspector if (Input.GetKeyDown("space")) { Vector2 position = player.position; RaycastHit2D hit = Physics2D.Raycast(position, player.position + playermovement.Direction * RayLength,~1 << 9); { Debug.Log("You have hit: " + hit.collider.name); } } } } EDITED: oh and here are my layers: I want every layer to respond with the collider .name except the player layer also edited script to be ~1<< 9
sorry I did not really reply to that Ok here is the error Assets/Scripts/Interaction_base.cs(12,48): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `Interaction_base.ignorePlayer' and it is referring to Code (CSharp): public LayerMask ignorePlayer = ~(1 << ignorePlayer);
Do this: Code (CSharp): at the variables: public LayerMask ignorePlayer; in Start: ignorePlayer = ~(1<<ignorePlayer); You didn't initialize the variable and you're trying to use it