I've added a mechanic into my game so that when the player collides with a trigger a button will appear for them to click, and once they do a player animation will activate.
Here's the script for that:
{
[SerializeField]
public Button enterButton;
public bool enterAllowed;
public Animator anim;
private void Start()
{
enterButton.gameObject.SetActive(false);
anim = GetComponent();
}
private void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("Temp Player"))
{
enterButton.gameObject.SetActive(true);
enterAllowed = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.name.Equals("Temp Player"))
{
enterButton.gameObject.SetActive(false);
enterAllowed = false;
}
}
public void Replenish()
{
anim.SetTrigger("isDrinking");
//Debug.Log("Player is drinking");
}
}
The script above is placed on the trigger which connects to the button on-click component. In it's inspector in Unity, I have the character's animator plugged in to the anim slot. The only problem present is when I play the game to test the mechanic, the anim slot automatically clears itself of the player's animator component.
![alt text][1]
![alt text][2]
Is there any way to fix this issue without having to replace the player's animator component whenever playing? I'm sorry if I lacked necessary details on my issue. If you need any questions answered, I'd be happy to oblige.
[1]: /storage/temp/168999-example-pic.png
[2]: /storage/temp/169000-example-pic2.png
↧