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 /
  • Help Room /
This question was closed Apr 25, 2018 at 11:20 AM by tormentoarmagedoom for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by karew1 · Feb 04, 2017 at 07:54 PM · audioaudiosourceaudioclipaudio.play

Audio Clip Error.

 using UnityEngine;
 using System.Collections;
 
 public class Player : MonoBehaviour 
 {
     public GameManager manager;
     public float moveSpeed;
     public GameObject deathParticles;
 
     private float maxSpeed = 5f;
     private Vector3 input;
 
     private Vector3 spawn;
 
     public AudioClip[] audioClip;
 
     public Rigidbody myRigidbody { get; private set; }
 
     // Use this for initialization
     void Start () 
     {
         spawn = transform.position;
         manager = manager.GetComponent<GameManager>();
 
         this.myRigidbody = this.GetComponent<Rigidbody>();
     }
     
     void FixedUpdate () 
     {
         input = new Vector3(Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
         if (myRigidbody.velocity.magnitude < maxSpeed)
         {
             myRigidbody.AddRelativeForce(input * moveSpeed);
         }
 
         if (transform.position.y < -2)
         {
             Die();
         }
     }
 
     void OnCollisionEnter(Collision Other)
     {
         if (Other.transform.tag == "Enemy")
         {
             Die();
         }
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.transform.tag == "Enemy")
         {
             Die();
         }
 
         if (other.transform.tag == "Token")
         {
             manager.tokenCount += 1;
             PlaySound(0);
             Destroy(other.gameObject);
         }
 
         if (other.transform.tag == "Goal")
         {
             manager.CompleteLevel();
             PlaySound(1);
         }
     }
 
     void PlaySound(int clip)
     {
         audio.clip = audioClip[clip];
         audio.Play();
     }
     
     void Die()
     {
             Instantiate(deathParticles, transform.position, Quaternion.Euler(270, 0, 0));
             transform.position = spawn;
     }
 }

The Code Problem

void PlaySound(int clip) { audio.clip = audioClip[clip]; audio.Play(); } "audio.clip" and "audio.Play();"

Unity Error;

Error 1 'UnityEngine.Component' does not contain a definition for 'clip' and no extension method 'clip' accepting a first argument of type 'UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

Error 2 'UnityEngine.Component' does not contain a definition for 'Play' and no extension method 'Play' accepting a first argument of type 'UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?)

Help me Pls :(

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
2
Best Answer

Answer by HenryStrattonFW · Feb 04, 2017 at 11:03 PM

Error 1 is a simple type casting issue. A lot of the old access properties (like audio, rigidbody, colider, etc) are no longer stored as their type, but as their base type "Component" this I believe was related to unity making their code base a bit more modular.

This is also why these properties are marked as "Deprecated" and should be phased out of use. I would advise using GetComponent to get the AudioSource component. like the following example.

 private AudioSource audioSource;
 
 void Awake()
 {
     audioSource = GetComponent<AudioSource>();
 }

Then play your audio through "audioSource" instead of "audio"

Error 2 is the same issue, since "audio" is type "Component" it does not have a method "Play" but when you swap to using an explicitly typed variable for your audioSource this should not be a problem.

Comment
Add comment · Show 5 · Share
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 karew1 · Feb 04, 2017 at 11:11 PM 0
Share

Thanks $$anonymous$$an :)

avatar image hossenshovon1 · Apr 23, 2018 at 07:50 PM 0
Share

This logic is not working

avatar image HenryStrattonFW hossenshovon1 · May 04, 2018 at 09:31 AM 0
Share

I assure you the logic provided is correct in the context of the issue it was given to address. If you're having problems with it can you provide some specifics as to how it is not working in your given situation? With more specifics I may be able to suggest potential fixes.

avatar image anyachris85 · Oct 28, 2018 at 02:17 AM 0
Share

Does this fix also work with transform, because am getting the same exact error when I use transform.length

I created a variable of spawn point of type transform with the [] , following a brackeys dodge block tutorial but its not working like it is on the tutorial am getting those 2 errors

UnityEngine.transform' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'UnityEngine.transform' could be found (are you missing a using directive or an assembly reference?)

avatar image HenryStrattonFW anyachris85 · Oct 28, 2018 at 02:43 AM 0
Share

The error there is saying that transform does not have a property or method 'length' which is completely true, you are trying to access a transform (singular) where it seems you're intending to access a transform array (an array does has a .length property).

Double check the variable you're accessing, chances are you're targeting the wrong variable, or have defined the variable as a transform ("Transform") ins$$anonymous$$d of an array ("Transform[]")

avatar image
0

Answer by hossenshovon1 · Apr 23, 2018 at 07:49 PM

This logic is not supporting , please say what to do

Comment
Add comment · Show 2 · Share
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 anyachris85 · Oct 28, 2018 at 02:16 AM 0
Share

Does this fix also work with transform, because am getting the same exact error when I use transform.length

I created a variable of spawn point of type transform with the [] , following a brackeys dodge block tutorial but its not working like it is on the tutorial am getting those 2 errors

UnityEngine.transform' does not contain a definition for 'length' and no extension method 'length' accepting a first argument of type 'UnityEngine.transform' could be found (are you missing a using directive or an assembly reference?)

avatar image alpsaruhan96 anyachris85 · Nov 24, 2020 at 08:13 PM 0
Share

I can't do audio. Can someone teach me =(((((

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to reduce delay when playing sound 0 Answers

Pick Up Sound 0 Answers

Why won't my second Audio Source play? 0 Answers

Audio won't play, no matter what code or method I try 0 Answers

How to mute multi-able audioclips within a single audiosource? 0 Answers


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