So, I was watching this video on YouTube and exactly followed each steps. Fortunately, everything went well. Until, I was further a platformer game and then tested it. No errors, just that the buttons clicked but did not responed. I came to a point until I created a new project just to check if there was some error with any other scripts causing this to happen. Nope, it still did not work. I again followed that video no result. You can notice in the images that I followed exactly everything. What do I do Anyways, heres the scene: Platformer game, character does not moves with pressing buttons aka scripts not responding at all, platform android
You need to add an event in the On Click() event you see above the “Axis Touch Button” script
and then assign the function you wish to call, you can google it or see the unity documentation for this
Okay, thanks. I got that all fixed. Now, there is only one thing that I need for a platformer. The most important thing after moving right and left. Aside from all the scrore and, making the camera follow the player and all that stuff: Jump
So here’s how it went. Also, I looked up a tutorial from the following video. Now, only the Jump dosen’t work. And this warning appears. Also, the other Jump script called “Jump” is a script from another video in which we touch (anywhere including the right and left buttons) to jump which is not what I want.
Also, I forgot to tell my expeterise. Anyways, my expertise level is: Noob, can create easter egg apps
Just read what the console message says, that’s the problem, your script can’t apply jump force because it doesn’t have a reference to the Rigidbody2D you have on your yellow character
Oh wait, the script you’re talking about is another script that is touch anywhere to jump. I just want the player’s body to jump when he clicks the specific button made to jump. Take a look at the code
//This script has been assigned to the player
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class CatControl : MonoBehaviour {
float dirX;
public float moveSpeed = 5f;
Rigidbody2D rb;
bool facingRight = true;
Vector3 localScale;
void Start () {
localScale = transform.localScale;
rb = GetComponent<Rigidbody2D> ();
}
void Update () {
dirX = CrossPlatformInputManager.GetAxis ("Horizontal");
}
void FixedUpdate()
{
rb.velocity = new Vector2 (dirX * moveSpeed, 0);
}
void LateUpdate()
{
CheckWhereToFace ();
}
void CheckWhereToFace ()
{
if (dirX > 0)
facingRight = true;
else if (dirX < 0)
facingRight = false;
if (((facingRight) && (localScale.x < 0)) || ((!facingRight) && (localScale.x > 0)))
localScale.x *= -1;
transform.localScale = localScale;
}
}
//This script has been assigned to the UI, refer to the above photo for the UI's configuration :)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TouchJump : MonoBehaviour
{
private Rigidbody2D rb;
private float jumpForce = 900f;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
rb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Force);
}
}
}