Search Unity

CrossPlatformInputManager Help!

Discussion in 'Animation' started by GeorgeSaint, Aug 16, 2018.

  1. GeorgeSaint

    GeorgeSaint

    Joined:
    Aug 16, 2018
    Posts:
    8
    Hello;)
    i'm just learning this awesome Engine Unity, so sorry for a stupid question but:
    My animation script don't work with touch screen controlls,
    Player moving animation working in 4 directions with Input.getAxisRow
    But with standard crossPlatformInputManager player animation stuck in idle state...
    Touch screen buttons work, keyboard work, but no animation with attached script for player

    Script for a player.
    Please lead me, tell where I'm wrong!
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityStandardAssets.CrossPlatformInput;

    public class TopDownMoveScript : MonoBehaviour
    {

    // Variables to hold Input directions in X and Y axses
    float MoveX, MoveY;
    private Animator anim;
    // Move speed variable can be set in Inspector with slider
    [Range(1f, 100f)]
    public float moveSpeed = 5f;
    void start()
    {
    anim = GetComponent<Animator>();
    }
    // Update is called once per frame
    void Update()
    {

    // Getting move direction according to button pressed
    // multiplied by move speed and time passed
    MoveX = CrossPlatformInputManager.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
    MoveY = CrossPlatformInputManager.GetAxis("Vertical") * moveSpeed * Time.deltaTime;

    // Setting new transform position of game object
    transform.position = new Vector2(transform.position.x + MoveX, transform.position.y + MoveY);

    anim.SetFloat("MoveX", CrossPlatformInputManager.GetAxis("Horizontal"));
    anim.SetFloat("MoveY", CrossPlatformInputManager.GetAxis("Vertical"));
    }
    }

    Big thanks!:)