Hi i want to trigger a scripted function in the animation window with an event on a specific frame, which is in another Gameobject, is this anyhow possible?
Thanks in advance
Hi i want to trigger a scripted function in the animation window with an event on a specific frame, which is in another Gameobject, is this anyhow possible?
Thanks in advance
Hi. I had the same problem but came up with a simple answer. Place a new blank script on the object with the animation. Make a blank function and call it from the animation event. Then in the blank function call the function from the other script you wanted on the other object. Worked for me. Hope it helps.
You’d need to create an intermediary script that stores a reference to the object you want to receive the event. Then you can sort of ‘pass it on’ when the event triggers.
I know this is an old post but maybe someone is wondering how to ‘pass on’ a reference to the other collider.
Since I’m a noob this took a while to figure out
public class triggerScript : MonoBehaviour
{
public GameObject animatedObject;
animationScript animationController;
private void Start()
{
animationController = animatedObject.GetComponent<animationScript>();
}
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.name == "TargetCube")
{
animationController.fadeSmall();
animationController.kObject = other.gameObject.GetComponent<Collider>();
}
}
}
public class animationScript : MonoBehaviour {
public Animator animator;
public Collider kObject;
public void fadeSmall()
{
animator.SetTrigger("fadeBackTrigger");
}
private void OnFadeComplete()
{
destroy(kObject);
}
private void destroy(Collider other)
{
other = kObject.GetComponent<Collider>();
Destroy(other.gameObject);
Debug.Log(other + " is destroyed");
}
}
Hi, please help me, i don’t know how to reference. I need to call animation from the script which is located in another gameobject. I need to do it immediately. Thanks…
I know this is super old, but here’s an example intermediary script that uses Unity Events.
using UnityEngine;
using UnityEngine.Events;
public class ToolAnimationEvents : MonoBehaviour {
public UnityEvent use;
public UnityEvent altUse;
public void Use() {
use.Invoke();
}
public void AltUse() {
altUse.Invoke();
}
}
Create as many unity events variables as you need with the associated method. It’s a bit easier and less messy than creating a specialized script for every use-case.