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

Animation Not Working

Discussion in 'Animation' started by ARares, Mar 19, 2016.

  1. ARares

    ARares

    Joined:
    Mar 18, 2016
    Posts:
    167
    My Recoil animation not working.

    Script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class WeaponAim : MonoBehaviour {
    6.  
    7.     Animator aim;
    8.  
    9.     public GameObject cross;
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.  
    14.         aim = GetComponent<Animator>();
    15.  
    16.         cross.SetActive(false);
    17.  
    18.     }
    19.    
    20.     // Update is called once per frame
    21.     void Update () {
    22.  
    23.         if (Input.GetButton("Fire2.0"))
    24.         {
    25.             aim.SetTrigger("NoAim");
    26.             cross.SetActive(false);
    27.         }
    28.         else
    29.         {
    30.             aim.SetTrigger("Aim1");
    31.             cross.SetActive(false);
    32.         }
    33.  
    34.         Recoil();
    35.     }
    36.  
    37.     void Recoil ()
    38.     {
    39.         if (Input.GetButton("Fire1"))
    40.         {
    41.             aim.SetTrigger("NoRecoil");
    42.         }
    43.         else
    44.         {
    45.             aim.SetTrigger("Recoil");
    46.         }
    47.     }
    48. }
    49.  
     
  2. 5vStudios

    5vStudios

    Joined:
    May 9, 2015
    Posts:
    106
    provide more detail
     
  3. ARares

    ARares

    Joined:
    Mar 18, 2016
    Posts:
    167
    I fixed:
    1. Aim Animation:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Aim : MonoBehaviour {
    6.  
    7.     public GameObject normalCamera;
    8.     public GameObject aimCamera;
    9.  
    10.     void Update () {
    11.  
    12.         if (Input.GetButtonDown("Fire2.0"))
    13.         {
    14.             normalCamera.SetActive(false);
    15.             aimCamera.SetActive(true);
    16.         }
    17.  
    18.         if (Input.GetButtonUp("Fire2.0"))
    19.         {
    20.             normalCamera.SetActive(true);
    21.             aimCamera.SetActive(false);
    22.         }
    23.     }
    24. }
    25.  
    2. Recoil:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class WeaponRecoil : MonoBehaviour {
    5.  
    6.     Animator recoil;
    7.  
    8.     // Use this for initialization
    9.     void Start()
    10.     {
    11.  
    12.         recoil = GetComponent<Animator>();
    13.  
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void Update()
    18.     {
    19.  
    20.         if (Input.GetButtonDown("Fire1"))
    21.         {
    22.             recoil.SetBool("Recoil1", true);
    23.         }
    24.  
    25.         if (Input.GetButtonUp("Fire1"))
    26.         {
    27.             recoil.SetBool("Recoil1", false);
    28.         }
    29.     }
    30. }
    31.