Answer the question
In order to leave comments, you need to log in
Animation transition not working on 2d platformer for android, unity 5?
Please help me solve the problem. the character walks on the buttons. But here's the problem =( Animation does not work.
anim.SetFloat ("Speed", Mathf.Abs (move));
by deleting various commands, I realized that this line is responsible for changing the animation. I inserted it into the script =>
using UnityEngine;
using System.Collections;
public class CharacterController1 : MonoBehaviour {
public Rigidbody2D rb2d;
public float speed;
public int move;
public bool groundCheck;
public bool facingRight = true;
Animator anim;
void Start ()
{
anim = GetComponent ();
rb2d = GetComponent();
}
void FixedUpdate ()
{
if ((move < 0) && (facingRight))
{
Flip();
}
if ((move > 0) && (!facingRight))
{
Flip();
}
groundCheck = true;
}
public void Move(int InputAxis)
{
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move)); <=========
move = InputAxis;
GetComponent().velocity = new Vector2 (move * speed, GetComponent().velocity.y);
if ((move < 0) && (facingRight))
{
Flip();
}
if ((move > 0) && (!facingRight))
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
Answer the question
In order to leave comments, you need to log in
Please close or delete your questions upon receipt of an answer or by the statute of limitations
using UnityEngine;
using System.Collections;
public class CharacterController1 : MonoBehaviour
{
public Rigidbody2D rb2d;
public float speed;
public int move;
public bool facingRight = true;
private Animator anim;
void Start()
{
anim = GetComponent<Animator> ();
rb2d = GetComponent<Rigidbody2D> ();
}
void FixedUpdate()
{
rb2d.velocity = new Vector2(move * speed, rb2d.velocity.y);
}
public void Update()
{
float move = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(move));
if ((move < 0) && (facingRight))
{
Flip();
}
if ((move > 0) && (!facingRight))
{
Flip();
}
}
void Flip()
{
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
}
}
The first thing that caught my eye should be:
anim = GetComponent ();
rb2d = GetComponent();
Second: is there an animator and animations on this object at all? Maybe the animator is not on this object, but on its child object? To check if the animator found it, you can right-click on the name of the Inspector tab and switch to Debug mode. Then all the variables of your CharacterController will be displayed, including the animator and see if Unity found it or not.
There are many more things that can affect.
And how did you understand that this line affects if the animation does not work? What other signs, errors in the console were there?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question