0
\$\begingroup\$

good day. When the motion button is pressed, the shape of the character changes and always goes to the left direction.

Why is this happening and what is the solution?

enter image description here

enter image description here

Pressing two buttons moves to the left and the shape changes.

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class PlayerKontrol : MonoBehaviour {

public float karakterHizi = 8f, maxSurat = 4f;
private Rigidbody2D myRigidbody;
private Animator myAnimator;


private bool solaGit, sagaGit;

void Awake () {
    myRigidbody = GetComponent<Rigidbody2D> ();
    myAnimator = GetComponent<Animator> ();

}

void FixedUpdate () {
    if (solaGit) {

        SolaGit ();
    }

    if (sagaGit) {

        SagaGit ();
    }
}

public void AyarlaSolaGit (bool solaGit)
{
    this.solaGit = solaGit;
    this.sagaGit = !solaGit;
}

public void HareketiDurdur () {
    solaGit = sagaGit = false;
    myAnimator.SetBool ("run", false);
}

void SolaGit (){

    float Xdurdur = 0f;
    float surat = Mathf.Abs (myRigidbody.velocity.x);

    if (surat < maxSurat)
        Xdurdur = -karakterHizi;

    Vector3 yon = transform.localScale;
    yon.x = -0.3f;
    transform.localScale = yon;

    myAnimator.SetBool ("run", true);

    myRigidbody.AddForce (new Vector2 (Xdurdur, 0));

}

void SagaGit () {

    float Xdurdur = 0f;
    float surat = Mathf.Abs (myRigidbody.velocity.x);

    if (surat < maxSurat)
        Xdurdur = -karakterHizi;

    Vector3 yon = transform.localScale;
    yon.x = 0.3f;
    transform.localScale = yon;

    myAnimator.SetBool ("run", true);

    myRigidbody.AddForce (new Vector2 (Xdurdur, 0));

}

}

\$\endgroup\$
  • \$\begingroup\$ It doesn't seem yout code snippets have the actual code that handles the buttons. \$\endgroup\$ – real4x Jan 17 at 7:57
  • \$\begingroup\$ The code provided is not in English. So we don't have a clue what's going on. Please translate your code so that we can better help you. \$\endgroup\$ – Alexandre Vaillancourt Jan 18 at 20:09
  • \$\begingroup\$ Also, you ask "what is the solution?". You state facts that could be an issue, but you don't state what you want to happen instead. \$\endgroup\$ – Alexandre Vaillancourt Jan 18 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.