Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by bruga94 · Dec 28, 2012 at 03:19 PM · collisioncell

Error Script Winning the Coconut Game (Surviving Island)

Sorry for the multiple questions but I'm a newbie u.u

It gaves me this error:

  • MissingComponentException: There is no 'AudioSource' attached to the "target" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "target". Or your script needs to check if the component is attached before using it. UnityEngine.AudioSource.PlayOneShot (UnityEngine.AudioClip clip) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/BaseClass.cs:504) TargetCollision+$targetHit$1+$.MoveNext () (at Assets/Scripts/TargetCollision.js:13) UnityEngine.MonoBehaviour:StartCoroutine(String) TargetCollision:OnCollisionEnter(Collision) (at Assets/Scripts/TargetCollision.js:8)

  • Assets/Scripts/CoconutWin.js(16,1): BCE0043: Unexpected token: winCell.

The first one is related to audio clips but I don't understand why, I inserted all the sound clips that I need :S

The second one is what is giving me the problem :(

Here is the script:

 #pragma strict
 static var targets : int = 0;
 static var haveWon : boolean = false;
 var winSound : AudioClip;
 var cellPrefab : GameObject;
 
 function Start () {
 
 }
 
 function Update () {
 
 if(targets==3 &&haveWon == false){
 targets=0;
 audio.PlayOneShot(winSound);
 winCell : GameObject = transform.Find("powerCell").gameObject;
 winCell.transform.Translate(-1,0,0);
 Instantiate(cellPrefab, winCell.transform.position,
 transform.rotation);
 Destroy(winCell);
 haveWon = true;
 }
 
 
 }
 @script RequireComponent(AudioSource)

Thanks guys for helping me so much, without you guys I would be anything on this project.

Comment
Add comment · Show 1
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 Lovrenc · Dec 28, 2012 at 03:32 PM 0
Share

1st question. Select gameObject in question and go to Components and add AudioSource. Sorry dont have time atm to read 2nd question.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Geo.Ego · Dec 28, 2012 at 03:36 PM

For the MissingComponentException, you need to make sure that the object you have attached your script to has an AudioSource component attached to it. In the Hierarchy window, click the object that the script is attached to, then go to Component > Audio > Audio Source in the top menu. This will attach the component and you should be good there.

For the unexpected token, you need to add "var" to the beginning of the declaration. So change this:

 winCell : GameObject = transform.Find("powerCell").gameObject;

to this:

 var winCell : GameObject = transform.Find("powerCell").gameObject;

It's strictly a syntactical issue.

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 bruga94 · Dec 28, 2012 at 05:34 PM 0
Share

could you post the code updated please because I didn't undersand very much the explanation

Thank u very much! And sorry for the inconveniences

avatar image Geo.Ego · Dec 28, 2012 at 07:41 PM 0
Share

No inconvenience. This is the place to go to learn, especially when you show, as you have, with written code that you've made an attempt in earnest and are hitting a wall. I updated my answer to show the exact code change. As far as adding the Audio Source, just follow the steps in the first paragraph and you'll be fine. If you still have trouble, tell me the name of the script and the name of the object you dragged it on to and I'll use those names to clarify further.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

How to prevent an object moving when there is a collision with the hand controlled by Leap Motion? 0 Answers

detecting rigidbody collsion with no extra script 1 Answer

Help with VR Controller Collider 1 Answer

Colliding Animation 0 Answers

Pausing/Waiting/Stopping code in a 2D Collision Function 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