warning CS0108: 'PlaneScript.audio' hides inherited member 'Component.audio'. Use the new keyword if

I get this error when i build my Application warning CS0108: ‘PlaneScript.audio’ hides inherited member ‘Component.audio’. Use the new keyword if hiding was intended

i only added ads to my App and now i get this error

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

public class PlaneScript : MonoBehaviour
{

    public float forwardSpeed = 3f;
    public float boostSpeed = 4f;

    private bool didFlap;

    private Rigidbody2D myRigidbody;
    private AudioSource audio;

    public GameManager gameManager;

    // Use this for initialization
    void Start()
    {
        myRigidbody = this.GetComponent<Rigidbody2D>();
        audio = GetComponent<AudioSource>();
        // Einfrieren deaktivieren
        Time.timeScale = 1f;
    }

    // Update is called once per frame
    void Update()
    {
        // Flugzeug fliegt entlang der X-Achse
        // Entsprechend gewünschter Geschwindigkeit
        Vector3 temp = transform.position;
        temp.x = temp.x + forwardSpeed * Time.deltaTime;
        transform.position = temp;

        if (didFlap)
        {
            // Button wurde gedrückt
            // Logik zum Aufsteigen des Flugzeugs
            myRigidbody.velocity = new Vector2(0, boostSpeed);
            // didFlap false
            didFlap = false;
        }
    }

    public void FlapThePlane()
    {
        Debug.Log("Button geklickt");
        didFlap = true;
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "RockHolder")
        {
            // Sound abspielen
            Debug.Log("Sound abspielen");
            audio.Play();
            // Punktestand +1 erhöhen
            gameManager.AddScore();
        }
    }

    void OnCollisionEnter2D(Collision2D other)
    {
        if (other.gameObject.tag == "Ground" || other.gameObject.tag == "Obstacle")
        {
            // Runde zu Ende
            gameManager.EndRound();
        }
    }

}

It’s exactly as the warning says. You defined a variable named “audio” in that script, which is already defined inside the base Component class. So either name it something else, or add the “new” keyword to the variable declaration.

Or update to 2019.2.7 where it was apparently removed.

2 Likes

To add to what @LiterallyJeff above said, which is 100% correct, the ‘audio’ property is an ancient Unity artifact (a shortcut to any AudioSource on that GameObject) that has been deprecated for 5+ years, and now apparently has been removed.

1 Like