[Help] Event Trigger buttons not working?

I have a left/right button for my 2D platformer, but they’re not working…

Here’s my Event Trigger for one of the buttons:

53153-c860287371194d88b8c9d6f4e2c55b65.png

I’m pretty sure these are set right, and here’s my PlayerController script:

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;
	float hInput = 0;
	
	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_ANDROID && !UNITY_IPHONE && !UNITY_BLACKBERRY && !UNITY_WINRT || UNITY_EDITOR
		Move(Input.GetAxisRaw("Horizontal"));
		if(Input.GetButtonDown("Jump"))
			Jump();
		#else
		Move (hInput);
		#endif
	}
	
	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;
	}
	
	public void StartMoving(float horizonalInput)
	{
		hInput = horizonalInput;
	}
}

I don’t know what’s wrong, they still don’t respond. The jump button works, but not left/right. Is it an error in my code? Please help! >.<

Hi BradenInman,

I have looked through your code and I am not sure why you call the Move Function twice in the fixed update function, maybe one is colliding with the other and causing an issue.

Also I am not sure but I think canMoveInAir is always equal to true therefore the function stops straight away, maybe if you tried some debug.log’s in those areas you could see where the error is occuring exactly and maybe removing the if (!canMoveInAir && !isGrounded) and possible using another if statement that works will help to solve the problem.

I think maybe isGrounded also may be causing a problem but I will need to check code further and test for myself but I thought I would try help before any of that :slight_smile:

Hope this helps.

Kind Regards,

IHackedDeath.