- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
jays99485 · Mar 24, 2015 at 06:21 AM ·
animationsanimation.play
Animations not playing
Hi, I want to play animations (left,right,up,down) that i did in Maya software .but i am not able to play , i really appreciate if someone could help me. please find the below script.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class PlayerControllerScript : MonoBehaviour {
public float speed = 1; // speed in meters per second
public float smooth = 2.0F;
private Vector2 fp; // first finger position
private Vector2 lp; // last finger position
private float horizontalMovement;
private float verticalMovement;
void Start()
{
animation.Play("idle");
}
// Update is called once per frame
void Update () {
Vector3 moveDir = Vector3.zero;
foreach(Touch touch in Input.touches)
{
if (touch.phase == TouchPhase.Began)
{
fp = touch.position;
lp = touch.position;
}
if (touch.phase == TouchPhase.Moved )
{
lp = touch.position;
if((fp.x - lp.x) > 80) // left swipe
{
animation.Play("left");
}
else if((fp.x - lp.x) < -80) // right swipe
{
animation.Play("right");
}
else if((fp.y - lp.y) < -80 ) // up swipe
{
animation.Play("up");
}
else if((fp.y - lp.y) > 80 ) // down swipe
{
animation.Play("down");
}
}
if(touch.phase == TouchPhase.Ended)
{
verticalMovement = 0;
horizontalMovement = 0;
}
}
float tiltAroundY = 0;
if(!isDecive)
{
moveDir.x = Input.GetAxis("Horizontal"); // get result of AD keys in X
moveDir.x = Input.GetAxis("Horizontal");
moveDir.y = Input.GetAxis("Vertical"); // get result of WS keys in Y
moveDir.y = Input.GetAxis("Vertical");
// move this object at frame rate independent speed:
tiltAroundY = Input.GetAxis("Horizontal") * tiltAngle;
}
else
{
moveDir.x = horizontalMovement; // get result of AD keys in X
moveDir.y = verticalMovement; // get result of WS keys in Y
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Animation2D help! 1 Answer
Animation not playing with animation.Play 1 Answer
Animation won't play EVERY time it is called 1 Answer
Import Animations FK 0 Answers
sync animations problem 1 Answer