Search Unity

Question Operator "==" cannot be applied to operands of type 'Footsteps.TextureSound' and 'Texture'

Discussion in 'Scripting' started by elcuci, Mar 14, 2023.

  1. elcuci

    elcuci

    Joined:
    Jun 13, 2021
    Posts:
    17
    Hello! I'm really stuck on this one. Why not?!?!? What does this mean exactly and why is this happening? Does anybody know? I'll post a snippet of my code, if there's something missing or any questions let me know. I don't usually post questions here because I feel like I can solve most things by myself, but this one I just don't know.

    Code (CSharp):
    1.     void PlayFootstepFromRenderer(Renderer Renderer)
    2.     {
    3.         foreach (TextureSound textureSound in TextureSounds)
    4.         {
    5.             //change maintex so that it works for other shaders, this is only for pro builder and standart
    6.             if (textureSound.Albedo == Renderer.material.GetTexture("_MainTex"))
    7.             {
    8.                 AudioClip clip = GetClipFromTextureSound(textureSound);
    9.                     audioSource.PlayOneShot(clip);
    10.                 }
    11.             }
    12.     }
    13.  
    14.     [System.Serializable]
    15.     private class TextureSound
    16.     {
    17.         public TextureSound Albedo;
    18.         public AudioClip[] Clips;
    19.     }
     
  2. Homicide

    Homicide

    Joined:
    Oct 11, 2012
    Posts:
    660
    Because a TextureSound is not a Texture2D
     
    elcuci likes this.
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Slow down, the answer is very simple: apples and oranges.

    Some help to fix "Cannot implicitly convert type 'Xxxxx' into 'Yyyyy':"

    http://plbm.com/?p=263
     
    elcuci and Homicide like this.
  4. elcuci

    elcuci

    Joined:
    Jun 13, 2021
    Posts:
    17
    Thank you for your answer! It was a pretty obvious answer now that I figured it out, turns out Texture autocorrected to TextureSound. I've now got some other issues that I may or may not post about lol.