Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using Spine.Unity;
- public class SpineboyMover : MonoBehaviour
- {
- // Use this for initialization
- public float speed = 5;
- public Transform graphics;
- public SkeletonAnimation skeletonAnimation;
- float x;
- string currentAnimation = "";
- void Update()
- {
- x = Input.GetAxis("Horizontal") * speed;
- if (x > 0) {
- graphics.localRotation = Quaternion.Euler(0, 0, 0);
- SetAnimation("run", true);
- }
- else if (x < 0) {
- graphics.localRotation = Quaternion.Euler(0, 180, 0);
- SetAnimation("run", true);
- }
- else{
- SetAnimation("idle", true);
- }
- }
- void SetAnimation(string name , bool loop){
- if (name == currentAnimation)
- return;
- skeletonAnimation.state.SetAnimation(0, name, loop);
- currentAnimation = name;
- }
- void FixedUpdate() {
- GetComponent<Rigidbody2D>().velocity = new Vector2(x, GetComponent<Rigidbody2D>().velocity.y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment