Problem changing texture of a gameobject in Unity

Asked

Viewed 698 times

0

I’m doing a job in Unity where the goal is to detect facial expressions with Kinect. In Unity the default expression is "neutral" and depending on we change expression to "smiling" or "overshadowing" the face it shows should change.

I used a gameobject which I called Face and assigned various textures and wanted it to alternate between them when we changed the expression, but for some reason it doesn’t want to work.

I’m using C#. I initially defined:

public static Texture[] textures = new Texture[7];
public Texture neutral, smiling, happy, angry, sad, kissing, surprised;
public GameObject Face;
public Renderer rend;

In the beginning I have this:

    player = GameObject.Find ("Face");

    textures[0] = neutral;
    textures[1] = smiling;
    textures[2] = happy;
    textures[3] = angry;
    textures[4] = sad;
    textures[5] = sad;
    textures[6] = surprised;

However he does not find the "Face", but I put for the inspector. No Update later do:

    ClassifyAndApply(numbers);

And this is set further down like this:

private void SaveAnimUnits()
    {
        numbers[0] = _animUnits.LipRaiser;
        numbers[1] = _animUnits.JawLowerer;
        numbers[2] = _animUnits.LipStretcher;
        numbers[3] = _animUnits.BrowLowerer;
        numbers[4] = _animUnits.LipCornerDepressor;
        numbers[5] = _animUnits.OuterBrowRaiser;
    }

    private void ClassifyAndApply(float[] units){

//      Renderer rend = GetComponent<Renderer>();
//      Face = GameObject.Find ("Face");



        if (units[2] <= 0.264888){
            if (units[3] <= 0.817408){
                if (units[1] <= 0.181886){
                    if (units[0] <= -0.216908){
                        if (units[4] <= 0.395523){
                            if (units[1] <= 0.104226){ 
                                Face. GetComponent<Renderer>().material.mainTexture = textures[3];
                            }
                            else{ 
                                Face. GetComponent<Renderer>().material.mainTexture = textures[0];
                            }

It’s just a piece of the decision tree. The problem is that it doesn’t change the texture when I do the expressions.

All help is welcome! Thank you

  • Hi André. A question that may seem kind of obvious: you separated the code from the decision tree with the texture update code, just to test? In other words, you made sure that the line that makes the texture change is in fact being executed (i.e., entered into all ifs of your code)?

1 answer

0


Thanks for the help,

I realized later that my problem was with Units[ ]. It did not receive the values.

As I used the Facetracking Starter kit from Unity’s Asset store, when I realized the game Object from the devil’s face, I stopped receiving the values for the Animation Units, which are these Units[ ] in this code.

When I activated it again, I received the values and it already worked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.