I have recently been doing some testing in a 3D project on Unity. In a 2D project I made, I sensed the player touching the ground by using “Collider2D.IsTouchingLayers(Ground)” and putting anything that classified as “ground” in the “Ground” layer. This strategy worked fine in that project, but I am now trying to use the same thing in 3D and it keeps saying “Collider does not contain a definition for IsTouchingLayers” Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
private Rigidbody rb;
private Collider boxColl;
private Collider capColl;
public bool canJump = false;
[SerializeField] private LayerMask Ground;
// Start is called before the first frame update
void Start()
{
rb = GetComponent();
boxColl = GetComponent();
capColl = GetComponent();
}
// Update is called once per frame
void Update()
{
if (Input.GetKey(KeyCode.Space) && capColl.IsTouchingLayers(Ground))
{
rb.velocity = new Vector3(rb.velocity.x, 7, rb.velocity.z);
}
}
}
Does anyone know what I’m doing wrong?