- Home /
Animation in android game not working
Hi, so I have this animation that needs to be played when the player is moving. It is working in the editor but it doesn't work on my android phone. Is there something wrong with my script?`public float speed=6f; Animator anim;
void Start(){
anim = GetComponent<Animator> ();
}
void Update () {
if (Input.touchCount == 1)
{
Touch touch = Input.touches[0];
if (touch.position.x > Screen.width/2){
transform.Translate(Vector2.right*speed*Time.deltaTime);
transform.eulerAngles = new Vector2(0,0);
}
else if (touch.position.x < Screen.width/2){
transform.Translate(Vector2.right*speed*Time.deltaTime);
transform.eulerAngles = new Vector2(0,180);
}
anim.SetFloat ("speed", Mathf.Abs (Input.GetAxisRaw("Horizontal")));
}
}`
I have a variable, speed, which is 0 when the player is still and it's set to 1 to make the player move.
Answer by TRG96 · Aug 23, 2014 at 05:12 PM
Problem with (Input.GetAxisRaw("Horizontal"))
This only works with keyboard and joystick. you need a different method of increasing or decreasing the speed with touch.
You can use TouchPhase.Began and TouchPhase.End to set the speed
thanks, I've tried with using UnityEngine; using System.Collections;
public class animation : $$anonymous$$onoBehaviour {
Animator anim;
// Use this for initialization
void Start () {
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
{
if (Input.touchCount=1)
anim.animation.Play ("walk");
}
{
if (Input.touchCount==0)
anim.animation.Stop("walk");
}
}
}
but it still doesn't work
Answer by Dubtoker · Feb 06, 2016 at 02:22 PM
Go into animation tab.. Right click rotation.. Change the interpolation property to quaternion ... Also works with camera animation.
Your answer
Follow this Question
Related Questions
i have a problem with Movement i need help 0 Answers
npc move when playing walk animation? 1 Answer
How do you move a character with physics when using Animator.setInteger to play the animations? 0 Answers
anim stream problems!! 0 Answers
changing the Animation by Player's position relative to the enemy 0 Answers