daily pastebin goal
9%
SHARE
TWEET

Untitled

a guest Jan 18th, 2018 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. [RequireComponent(typeof(Animator))]
  6. public class MoveCharacter : MonoBehaviour
  7. {
  8.     private int idX = Animator.StringToHash("x"), idY = Animator.StringToHash("y");
  9.     private Animator animator = null;
  10.  
  11.     void Start ()
  12.     {
  13.         animator = GetComponent<Animator> ();
  14.     }
  15.    
  16.     void Update ()
  17.     {
  18.         float x = Input.GetAxisRaw ("Horizontal");
  19.         float y = Input.GetAxisRaw ("Vertical");
  20.  
  21.         if (Mathf.FloorToInt(x) != 0 || Mathf.FloorToInt(y) != 0) {
  22.             animator.SetFloat (idX, x);
  23.             animator.SetFloat (idY, y);
  24.  
  25.             transform.localPosition += new Vector3 (x, y) * 0.05f;
  26.         }
  27.     }
  28. }
RAW Paste Data
Top