- Home /
trying to link an aniamtion in one script to a action in another
im making a fps game and I want to switch the enemy animation once the player enters his field of view which is a trigger on another object however when I try to link both scripts into activating the animation when the player enters the trigger a problem occurs
so basically scrip A says:
public void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
detected = true;
target = other.gameObject;
}
}
and I want to make script B say:
if (PlayerLookScript.detected == true)
{
animator.SetBool("IsShootingStill", true);
}
but it keeps giving me errors but I don't know why
My guess would be something like once the player enters his PoV trigger just have his PoV trigger tell his animator directly to change animation either by having a public reference that you can drag & drop in the editor [gameObject.getComponent().SetBool("IsShootingStill", true);] or by navigating to it in the parent/child hierarchy.
I tried to do this once but because the animator is controlling the enemy object and not the POv object it says the itdoesnt work
public class PlayerLookScript : MonoBehaviour
{
// set as static
public static bool detected;
private GameObject target;
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
detected = true;
target = other.gameObject;
}
}
}
public class EnemyShootScript : MonoBehaviour
{
Animator animator;
private void Start()
{
animator = GetComponent<Animator>();
}
private void Update()
{
if (PlayerLookScript.detected == true)
{
animator.SetBool("IsShootingStill", true);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613025911im_/https://answers.unity.com/themes/thub/images/avi.jpg)