Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

2d bug

Discussion in '2D' started by 787gabriel777, Feb 1, 2017.

  1. 787gabriel777

    787gabriel777

    Joined:
    Jul 20, 2015
    Posts:
    65
    i have a little problem with my animations
    any of my animations start, just the idle...
    i just put a animator, and, all my animation into, so i created a code and a parameter

    this is all the code that i used
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class mov_char : MonoBehaviour {
    5.  
    6.  
    7.     public float speed;
    8.     private SpriteRenderer myrender;
    9.     private bool fight;
    10.  
    11.  
    12.      Animator anim;
    13.  
    14.  
    15.  
    16.     // Use this for initialization
    17.     void Start () {
    18.  
    19.         speed = 2.0f;
    20.         myrender = GetComponent<SpriteRenderer> ();
    21.         fight = false;
    22.         anim = GetComponent<Animator>();
    23.  
    24.    
    25.     }
    26.    
    27.     // Update is called once per frame
    28.     void Update(){
    29.  
    30.         mov ();
    31.  
    32.  
    33.  
    34. }
    35.  
    36.     void mov(){
    37.  
    38.         if (Input.GetAxisRaw ("Horizontal") < 0) {
    39.    
    40.             transform.Translate (Vector2.right * speed * Time.deltaTime);
    41.             myrender.flipX = false;
    42.             anim.SetInteger ("valores_ani", 2);
    43.        
    44.         } else {
    45.        
    46.             anim.SetInteger ("valores_ani", 1);
    47.         }
    48.         if (Input.GetAxisRaw("Horizontal") > 0) {
    49.  
    50.  
    51.             transform.Translate (-Vector2.right * speed * Time.deltaTime);
    52.             myrender.flipX = true;
    53.             anim.SetInteger ("valores_ani", 2);
    54.  
    55.         }else {
    56.  
    57.             anim.SetInteger ("valores_ani", 1);
    58.         }
    59.  
    60.         if (Input.GetMouseButtonDown (0)) {
    61.        
    62.             print ("atck!");
    63.             anim.SetInteger ("valores_ani", 3);
    64.        
    65.         }
    66.  
    67.         if (Input.GetMouseButtonUp (0)) {
    68.        
    69.             print("not attacking!");
    70.             anim.SetInteger ("valores_ani", 1);
    71.        
    72.         }
    73.  
    74.  
    75.  
    76.     }
    77. }
     
  2. chipthief

    chipthief

    Joined:
    Feb 1, 2017
    Posts:
    1
    Did you set up the animation transitions to trigger when you change valores_ani?
     
  3. 787gabriel777

    787gabriel777

    Joined:
    Jul 20, 2015
    Posts:
    65
    i think no, how can i do it ?