Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Oct 07, 2016 at 10:14 AM by lyrha for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by lyrha · Oct 07, 2016 at 10:33 AM · camerasound

An object reference is required to access non-static member `UnityEngine.Component.GetComponent(System.Type)'

Hello, i want to play and stop my music in my game, i don't have any problem when I do stop, but when I do play, appears this message "An object reference is required to access non-static member `UnityEngine.Component.GetComponent(System.Type)' "

this is my code:

using UnityEngine; using System.Collections; using UnityEngine.UI;// we need this namespace in order to access UI elements within our script

public class audio : MonoBehaviour {

 public bool soundoff = true;
 public Button botonSoundOn; 
 public Button botonSoundOff; 
 

 public void start(){
     botonSoundOn = botonSoundOn.GetComponent<Button> ();
     botonSoundOff = botonSoundOff.GetComponent<Button> ();

 }

 public void PararSonido(){
     Camera.main.GetComponent<AudioSource>().Stop();
     soundoff = false;
 }
 public void PonerSonido(){
     Camera.GetComponent<AudioSource>().Play();

     Debug.Log ("entras");
     soundoff = true;

 }

}

Please help!

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image saud_ahmed020 · Oct 07, 2016 at 10:55 AM 0
Share

@lyrha Just replace the Camera.GetComponent<AudioSource>().Play(); by Camera.main.GetComponent<AudioSource>().Play();

avatar image lyrha saud_ahmed020 · Oct 07, 2016 at 11:03 AM 0
Share

yes, that's the solution, I solved it , I thought I had closed the subject, thanks anyway

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to have multiple game objects play a single looping sound 2 Answers

Third person Camera With Lerp trouble 0 Answers

How to make camera position relative to a specific target. 1 Answer

How can i make sound when the gameobject exit the camera? 1 Answer

Sound OnTriggerEvent with HTC Vive Camera (head) wont play. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges