Access Animator Controller from other objects?

Hey guys, I made a simple camera shake state and animation in Mecanim. I have a player character and I want it to trigger this camera shake when he actually shoots. My shoot script is here below:

using UnityEngine;
using System.Collections;

public class PlayerShoot : MonoBehaviour
{
    public GameObject bullet;
    public string shotButton = "Fire1";
    public float shotDelay = 0.2f;
    private bool readyToShoot = true;
 
    // Update is called once per frame
    void Update ()
    {
        {
            if(Input.GetButton(shotButton) && readyToShoot)
            {
                if(audio != null)
                {
                    if(!audio.isPlaying)
                    {
                        audio.Play();
                    }
                }
                Instantiate(bullet,transform.position,transform.rotation);
                readyToShoot = false;
                Invoke("ResetReadyToShoot", shotDelay);
            }
        }
    }
   
    void ResetReadyToShoot()
    {
        readyToShoot = true;
    }
}

So every 0.2 seconds my character shoots. I also want it to play the camera shake animation every 0.2 seconds. My issue is I have no idea how to do this. I added a bool parameter in the cameraController called “Shake” and set it as the transition condition for the camera to go from idle to shaking.

How do I actually set that bool to true all the way from my player’s shooting script?

Just create a var for the scipt you want to access in you player script. Preferably, set it in the editor.

public someScript someScript_data;
1 Like

Thank you for reply mate.

What I ended up doing is a bit hacky, but works brilliantly so far. I added a big collider to the camera and put it on a layer called “CameraCollider”. I put a script on the camera that sais whenever something enters this trigger collider “shake” must be set to true. And it must be set to false after .3 seconds. I then adjusted the collision matrix so that player bullets and explosions can collide with camera, and nothing else. So far this is working flawlessly.