So, im trying to make the movement for my game based on tapping the keys and not holding them, it works in touch screen when the code has if(input.GetAxisRaw(Horizontal));
However, on computers, i can hold to move left and right, but the jumping sequence is tap based. I then tried to mimic the jump code which is:
if(Input.GetButtonDown("Jump"))
Jump();
//and then it was defined with:
public void Jump()
{
if(isGrounded)
myBody.velocity += jumpVelocity * Vector2.up;
}
I tried to mimic this with a “move” function, but i got the error “No overload for method ‘move’ takes 0 arguments”
Here is the full code(which comes up with the error, of course), hopefully someone has a solution. Thank you!
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour
{
public float speed = 10, jumpVelocity = 10;
public LayerMask playerMask;
public bool canMoveInAir = true;
Transform myTrans, tagGround;
Rigidbody2D myBody;
bool isGrounded = false;
void Start ()
{
// myBody = this.rigidbody2D;//Unity 4.6-
myBody = this.GetComponent<Rigidbody2D>();//Unity 5+
myTrans = this.transform;
tagGround = GameObject.Find (this.name + "/tag_ground").transform;
}
void FixedUpdate ()
{
isGrounded = Physics2D.Linecast (myTrans.position, tagGround.position, playerMask);
#if !UNITY_STANDALONE_WINDOWS && !UNITY_STANDALONE_OSX && !UNITY_ANDROID && !UNITY_IPHONE && !UNITY_BLACKBERRY && !UNITY_WINRT || UNITY_EDITOR
if(Input.GetButtonDown("Move"))
Move();
if(Input.GetButtonDown("Jump"))
Jump();
#endif
}
public void Move(float horizonalInput)
{
if(!canMoveInAir && !isGrounded)
return;
Vector2 moveVel = myBody.velocity;
moveVel.x = horizonalInput * speed;
myBody.velocity = moveVel;
}
public void Jump()
{
if(isGrounded)
myBody.velocity += jumpVelocity * Vector2.up;
}
}