Hello guys,
he read like thousand posts, but i can't resolve my problem, i know it so easy but i can't 😃 .
I have 6 animations in my Player character, and i want change the animations if i press W (Jump), or D (Run) or if i dead (Dead).
I try this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using Spine;
using Spine.Unity;
public class PlayerController02 : MonoBehaviour {
//variables publicas
public float speed = 5f;
public float jumpForce = 100f;
public Animator animPlayer;
public SkeletonAnimation skeletonPlayer;
public UnityEvent pauseGame;
public UnityEvent unpauseGame;
//variables privadas
private bool isGrounded = false;
private bool scalePortal1;
private bool scalePortal2;
private Rigidbody2D rbPlayer;
private float moveHorizontal;
private float distance;
private float firstDistance;
private Vector3 startingScale;
// Use this for initialization
void Start () {
rbPlayer = gameObject.GetComponent<Rigidbody2D> ();
animPlayer = gameObject.GetComponent<Animator>();
startingScale = transform.localScale;
}
// Update is called once per frame
void FixedUpdate () {
moveHorizontal = Input.GetAxis ("Horizontal");
transform.Translate (Vector2.right * moveHorizontal * speed * Time.deltaTime);
if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow))
{
skeletonPlayer.state.SetAnimation(0, "Corre", true);
}
else
{
skeletonPlayer.state.SetAnimation(0, "Idle", true);
}
if (Input.GetKeyDown (KeyCode.W) && isGrounded) {
rbPlayer.AddForce (Vector2.up * jumpForce);
isGrounded = false;
skeletonPlayer.state.SetAnimation(0, "Salta", true);
}
else
{
skeletonPlayer.state.SetAnimation(0, "Idle", true);
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (Time.timeScale == 1f)
{
pauseGame.Invoke();
}
else
{
unpauseGame.Invoke();
}
}
}
private void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
isGrounded = true;
}
}
void OnCollisionExit2D(Collision2D col){
if(col.gameObject.CompareTag("Ground")){
isGrounded = false;
}
}
}
I don't know if the problem is in code or in Unity.