- Home /
Some more errors: CS0117, CS1502, CS1503, CS0162
In my code I get the errors:
Assets/2d prefabs/Scripts/Move2.cs(59,102): error CS0117: UnityEngine.PointEffector2D' does not contain a definition for position'
Assets/2d prefabs/Scripts/Move2.cs(59,68): error CS1502: The best overloaded method match for UnityEngine.Physics2D.OverlapCircleAll(UnityEngine.Vector2, float, int)' has some invalid arguments
Assets/2d prefabs/Scripts/Move2.cs(59,68): error CS1503: Argument #1' cannot convert object' expression to type UnityEngine.Vector2'
Assets/2d prefabs/Scripts/Move2.cs(64,55): warning CS0162: Unreachable code detected
My code is: using UnityEngine; using System.Collections;
public class Move2 : MonoBehaviour {
private Rigidbody2D myRigidbody;
[SerializeField]
private float movementSpeed;
[SerializeField]
private Transform[] groundPoints;
[SerializeField]
private float groundRadius;
[SerializeField]
private LayerMask whatIsGround;
private bool isGrounded;
private bool jump;
[SerializeField]
private float jumpForce;
// Use this for initialization
void Start ()
{
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate ()
{
isGrounded = IsGrounded ();
float horizontal = Input.GetAxis ("Horizontal");
Debug.Log ("Horizontal");
HandleMovement (horizontal);
}
private void HandleMovement(float horizontal)
{
myRigidbody.velocity = new Vector2 (horizontal * movementSpeed, myRigidbody.velocity.y);
if (isGrounded && jump)
isGrounded = false;
myRigidbody.AddForce (new Vector2 (0, jumpForce));
}
private void HandleInput()
{
if(Input.GetKeyDown(KeyCode.UpArrow))
{
jump = true;
}
}
private void ResetValues()
{
jump = false;
}
private bool IsGrounded()
{
if (myRigidbody.velocity.y <= 0) {
foreach (Transform point in groundPoints) {
Collider2D[] colliders = Physics2D.OverlapCircleAll (PointEffector2D.position, groundRadius, whatIsGround);
for (int i = 0; i < colliders.Length; i++) {
if (colliders [i].gameObject != gameObject) {
return true;
Debug.Log ("it is Grounded");
}
}
}
}
return false;
}
}
Thanks for your help! @JedBeryll
Answer by doublemax · Oct 06, 2016 at 08:13 AM
Collider2D[] colliders = Physics2D.OverlapCircleAll (PointEffector2D.position, groundRadius, whatIsGround);
"PointEffector2D.position" should probably be "point.position".
Thank you! I'll try that. What about the other errors? @doublemax
I believe all errors are caused by the same problem. The reason for the warning should be obvious...
Now I am having another issue where jump is permanently triggered, do you know what could cause that?
ResetValues() is never called and "jump" is never reset to false again.
This is a very beginner question but how do i call ResetValues()? I thought it would be called as is, what did I do wrong?
Try this:
if (isGrounded && jump)
{
isGrounded = false;
myRigidbody.AddForce (new Vector2 (0, jumpForce));
ResetValues ();
}
( Going offline soon, so no more answers from me in the next hours :) )
Now it won't jump at all, but at least it isn't stuck going up. Thank you for your help so far! Once you get back online, do you know what the problem is?
Your answer
Follow this Question
Related Questions
moving player top down,movement in unity 2d 0 Answers
How to make a sprite respond to a specific color? 0 Answers
When 2D Car Turns Upside Down, Game Over Scene Should appear. 1 Answer
Stuttering in simple 2D game using interpolation? 1 Answer
Why Is there A slight jitteryness on player movement and camera? 0 Answers