After the player changing location (moved from the one scene to another), player running in one direction, if using keyboard everything are normal, but when i uses buttons on screen, there is such a problem. Plz help if you can, thanks.(I’m rookie)
Please explain your problem in more detail. Explain exactly what is going wrong. What you want it to be doing. What errors are popping up, if any. What you have tried doing to solve the issue. If you think its a code issue, post your code (using code tags please)
Users cannot help with vague issues of “It isnt working on mobile”. Also, place debug.logs in your code to help yourself finding the issue(s).
When I changing scene by special trigger player is running in one way. But when I off script and using another, without crossplatform, its working.
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerCtrl : MonoBehaviour
{
public float moveSpeed;
private float currentMoveSpeed;
public float diagonalMoveModifier;
private Animator anim;
private Rigidbody2D myRigidbody;
private bool playerMoving;
public Vector2 lastmove;
private static bool playerExists;
private bool attacking;
public float attackTime;
private float attackTimeCounter;
public string startPoint;
public bool canMove;
// Start is called before the first frame update
void Start()
{
anim = GetComponent<Animator>();
myRigidbody = GetComponent<Rigidbody2D>();
if(!playerExists)
{
playerExists = true;
DontDestroyOnLoad(transform.gameObject);
} else
{
Destroy(gameObject);
}
canMove = true;
}
// Update is called once per frame
void Update()
{
playerMoving = false;
if(!canMove)
{
myRigidbody.velocity = Vector2.zero;
return;
}
if (!attacking)
{
if (Input.GetAxisRaw("Horizontal") > 0.5f || Input.GetAxisRaw("Horizontal") < -0.5f)
{
//transform.Translate(new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
myRigidbody.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * currentMoveSpeed, myRigidbody.velocity.y);
playerMoving = true;
lastmove = new Vector2(Input.GetAxisRaw("Horizontal"), 0f);
}
if (Input.GetAxisRaw("Vertical") > 0.5f || Input.GetAxisRaw("Vertical") < -0.5f)
{
//transform.Translate(new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, Input.GetAxisRaw("Vertical") * currentMoveSpeed);
playerMoving = true;
lastmove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}
if (Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
{
myRigidbody.velocity = new Vector2(0f, myRigidbody.velocity.y);
}
if (Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
{
myRigidbody.velocity = new Vector2(myRigidbody.velocity.x, 0f);
}
if (Input.GetKeyDown(KeyCode.J))
{
attackTimeCounter = attackTime;
attacking = true;
myRigidbody.velocity = Vector2.zero;
anim.SetBool("Attack", true);
}
if (Mathf.Abs(Input.GetAxisRaw("Horizontal")) > 0.5f && Mathf.Abs(Input.GetAxisRaw("Vertical")) > 0.5f)
{
currentMoveSpeed = moveSpeed * diagonalMoveModifier;
} else
{
currentMoveSpeed = moveSpeed;
}
}
if (attackTimeCounter > 0)
{
attackTimeCounter -= Time.deltaTime;
}
if (attackTimeCounter <= 0)
{
attacking = false;
anim.SetBool("Attack", false);
}
anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", lastmove.x);
anim.SetFloat("LastMoveY", lastmove.y);
}
}
So, if i am understanding correctly, the above script is working without crossplatform being active? And when Crossplatform is active, it isnt working? When you say “player is running in one way”, is that supposed to be happening or no? Is he supposed to be able to go both directions?
Yes when I use crossplatform its isnt working and yes he supposted to run in both diractions