Question by
gustavodiniz-b · Apr 25, 2018 at 07:33 PM ·
errorlayers
IsTouchingLayers problem. It dont work
can someone help me with IsNotTouchingLayers? : code if (Input.GetButtonDown("Jump") && foot IsTouchigLayers (ground) { body.AddForce(Vector2.up * jumpForce);
Comment
Answer by vinilly · Apr 25, 2018 at 08:31 PM
[SerializeField] private float groundCheckRadius;
[SerializeField] private bool isGrounded;
[SerializeField] private float jumpForce;
public Transform groundCheck; //Drag an empty game Object to this and put it on the feet (TheSprite)
private Rigidbody2D body;
//private Animator myAnim;
public LayerMask whatisGround;
void Start() {
jumpForce = 1.0f;
groundCheckRadius = 0.5f;
//myAnim = GetComponent<Animator> ();
body = GetComponent<Rigidbody2D> ();
}
void Update{
if (Input.GetButtonDown("Jump") && _isGrounded)
{
body.velocity = new Vector3(body.velocity.x, _jumpSpeed, 0f);
}
}
void FixedUpdate()
{
if (Input.GetButtonDown("Jump") && _isGrounded)
{
body.velocity = new Vector3(body.velocity.x, _jumpForce, 0f);
}
}
private void LateUpdate()
{
GroundChecker();
}
private void GroundChecker()
{
isGrounded = Physics2D.OverlapCircle
(groundCheck.position,
groundCheckRadius,
whatisGround); //Sets bool to true
//myAnim.SetFloat("Speed", Mathf.Abs( body.velocity.x));
//myAnim.SetBool("Grounded", isGrounded);
}
vote me up to keep me around.
Your answer
![](https://koobas.hobune.stream/wayback/20220612161520im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to solve this error 0 Answers
Initialize menu (busy for) 0 Answers
error loaded unityframework,Error loading Unityframework 0 Answers
How do I add an already built and textured set in unity? 0 Answers
Making raycast ignore multiple layers 6 Answers