Two animations for different things(Aiming and Hip Fire)

So i have the code as follows

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class adsGlock : MonoBehaviour {

    public Animator animator;
    public ParticleSystem muzzleFlash;
    public Animation shootAds;
    public Animation shootHip;

    private bool isGlockAiming = false;
    private bool isShootAds = false;

    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Mouse1))
            isGlockAiming = !isGlockAiming;
            animator.SetBool("isAimingGlock", isGlockAiming);
        if (isGlockAiming == false && Input.GetKeyDown(KeyCode.Mouse0))
            Debug.Log("Shot while hip fire");
        if (isGlockAiming == true && Input.GetKeyDown(KeyCode.Mouse0))
            Debug.Log("Shot while ads");

so i need to have two animations on one object but it does not let me do that. does anyone know another way i can handle this.


This isn’t the “right way” to do this, but I found a solution for this very problem just the other day. I had an NPC who walked around town, using, of course, a walking animation. I needed his animation to becoming a talking animation when the player began a conversation with him. The solution?

#pragma strict

var Speaking : boolean = false;
var Entered : boolean = false;
var theselines : String;
var Background : GameObject;
var AIMovementScript : AIMovement;
var MouseLookScript : MouseLook;
var MouseLookScript2 : MouseLook;
var Textholder : GameObject;
public var guiSkin : GUISkin;
//var TalkSound : AudioClip;
var Man_1 : GameObject;
var Man_2 : GameObject;

function OnTriggerEnter (col : Collider) {
if(col.gameObject.tag == "Player") { = false; = true;
Entered = true;


function OnTriggerExit (col : Collider) {
if(col.gameObject.tag == "Player") {
Entered = false; = true; = false; = false; = false;
AIMovementScript.enabled = true; 
MouseLookScript.enabled = true; 
MouseLookScript2.enabled = true; 
 function Outtahere(){
yield WaitForSeconds(3);
Speaking = false;
// = false;

function OnGUI(){
if(Entered){ = true; = true;
AIMovementScript.enabled = false;
MouseLookScript.enabled = false;
MouseLookScript2.enabled = false;
//AudioSource.PlayClipAtPoint(TalkSound, transform.position);
Speaking = true; = guiSkin;
//GUI.Label(Rect(500,525,400,175), "Press 'O' to speak");

if(Speaking){ = guiSkin;
GUI.Label(Rect(500,320,400,175), theselines);


Make an empty game object as the parent to two identical game objects, each with a different animation. (In my case, a 3d model of a person.) One model is active, while the other is not. At a certain trigger point, enable one model (with its animation) and disable the other. It’s probably not the “correct” solution, but it works very well for me. BTW, I know my answer is in js, but figured if you got this far you know how to do what I’m doing, but in C.