#Animator issues

1 messages · Page 1 of 1 (latest)

chilly leaf
#

for some reason the open animation has no issue playing but the closed one wont

#

<@&823670121133768714>

broken gale
#

[]nocode

winged parcelBOT
#

It's hard to answer a programming question without code

Resolving a bug is almost impossible when the question doesn't include any of the buggy code. In order to help fix the problem, answerers are going to have to see what the code is.
Source: https://idownvotedbecau.se/nocode

Please isolate the problematic code and send it as a codeblock. If you don't know how to send a codeblock, type []cb

chilly leaf
#

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

public class OpenDrawer : MonoBehaviour
{
public Animator ANI;

public GameObject openText;
public GameObject closedText;

public AudioSource openSound;
public AudioSource closeSound;

private bool open;

private bool inReach;


void Start()
{
    openText.SetActive(false);
    closedText.SetActive(false);

    ANI.SetBool("Open", false);
    ANI.SetBool("Closed", false);

    open = false;
}

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "Reach" && !open)
    {
        inReach = true;
        openText.SetActive(true);
    }

    else if (other.gameObject.tag == "Reach" && open)
    {
        inReach = true;
        closedText.SetActive(true);
    }
}

void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "Reach")
    {
        inReach = false;
        openText.SetActive(false);
        closedText.SetActive(false);
    }
}



void Update()
{
    if (inReach && Input.GetButtonDown("Interact"))
    {
        openSound.Play();
        Debug.Log("it works dumbass");
        ANI.SetBool("Open", true);
        ANI.SetBool("Closed", false);
        open = true;
        openText.SetActive(false);
        inReach = false;
        ANI.SetBool("Open", false);
    }

    else if (inReach && Input.GetButtonDown("Interact"))
    {
        ANI.SetBool("Open", false);
        closeSound.Play();
       ANI.SetBool("Closed", true);
        open = false;
        closedText.SetActive(false);
        inReach = false;
    }

}

}

#

the issue is the open bool wont turn off and the cosed bool wont turn on

chilly leaf
chilly leaf
chilly leaf
#

@broken gale

broken gale
#

no idea sadly

chilly leaf
#

ok thanks anyways

gusty nest
#

Maybe look into using Animator.SetTrigger() instead, it seems like using SetBool() is getting redundant here since you're setting each book every time

chilly leaf
#

Ok thanks man will try it out

chilly leaf
#

@gusty nest what code do i use to activate a trigger

gusty nest
#

SetTrigger()

chilly leaf
#

its didnt work 😦

#

i tried taht

#

@gusty nest

gusty nest
#

send code

#

did you make a trigger parameter in the animator

chilly leaf
#

yeh

#

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

public class OpenDrawer : MonoBehaviour
{
public Animator ANI;

public GameObject openText;
public GameObject closedText;

public AudioSource openSound;
public AudioSource closeSound;

private bool open;
private bool closed;

private bool inReach;


void Start()
{
    openText.SetActive(false);
    closedText.SetActive(false);
    
    

    closed = true;
    open = false;
}

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "Reach" && !open)
    {
        inReach = true;
        openText.SetActive(true);
    }

    else if (other.gameObject.tag == "Reach" && open)
    {
        inReach = true;
        closedText.SetActive(true);
    }
}

void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "Reach")
    {
        inReach = false;
        openText.SetActive(false);
        closedText.SetActive(false);
    }
}



void Update()
{
    if (inReach && Input.GetButtonDown("Interact"))
    {
        openSound.Play();
        Debug.Log("it works dumbass");
        ANI.SetTrigger("Open");
        
        open = true;
        openText.SetActive(false);
        inReach = false;
        ANI.SetBool("Open", false);
    }

    else if (inReach && Input.GetButtonDown("Interact"))
    {
        
        closeSound.Play();
       ANI.SetTrigger("Closed");
        
        open = false;
        closedText.SetActive(false);
        inReach = false;
    }

}

}

gusty nest
#

[]cb

winged parcelBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

chilly leaf
#

Console.WriteLine("using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OpenDrawer : MonoBehaviour
{
public Animator ANI;

public GameObject openText;
public GameObject closedText;

public AudioSource openSound;
public AudioSource closeSound;

private bool open;
private bool closed;

private bool inReach;


void Start()
{
    openText.SetActive(false);
    closedText.SetActive(false);
    
    

    closed = true;
    open = false;
}

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.tag == "Reach" && !open)
    {
        inReach = true;
        openText.SetActive(true);
    }

    else if (other.gameObject.tag == "Reach" && open)
    {
        inReach = true;
        closedText.SetActive(true);
    }
}

void OnTriggerExit(Collider other)
{
    if (other.gameObject.tag == "Reach")
    {
        inReach = false;
        openText.SetActive(false);
        closedText.SetActive(false);
    }
}



void Update()
{
    if (inReach && Input.GetButtonDown("Interact"))
    {
        openSound.Play();
        Debug.Log("it works dumbass");
        ANI.SetTrigger("Open");
        
        open = true;
        openText.SetActive(false);
        inReach = false;
        ANI.SetBool("Open", false);
    }

    else if (inReach && Input.GetButtonDown("Interact"))
    {
        
        closeSound.Play();
       ANI.SetTrigger("Closed");
        
        open = false;
        closedText.SetActive(false);
        inReach = false;
    }

}

}");

gusty nest
#

not "

#

`

#

below escape

#

before and after the whole codeblock

#

why are you still using SetBool()?

#

you're supposed to replace the SetBool Logic to SetTrigger

chilly leaf
#

where

#

oh there

#

@gusty nest still doesnt work

#

it opens but doesnt close

#

do i reset trigger

#

@gusty nest

#

ok it works kind of

#

@gusty nest it works amazing but waht is happening is i copy and pasted the drawers to make a 3 stack and now it opens fine the first time on the pasted drawers but the secondi t screws up the animatio