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 /
avatar image
0
Question by Inan-Evin · May 19, 2011 at 07:48 PM · pointpoints

Problem About Gaining Points

Hello everyone, i have 107 golds in my scene and we need to collect them, i wrote a code but it takes the first one, but it doesn't take the second one, what can be the problem ?

Here it's :

 var distance = 100;
 var gold : Transform;
 var blipsound : GameObject;
 var gold2 : Transform;
 
 
 
 
 
 
 function Update ()
 {
 
 GameObject.Find("g_Points").guiText.text = ""+PointCode.points;
 
 if(Vector3.Distance(transform.position,gold.position) < distance)
 {
     GainPoints();
    }
 else if (Vector3.Distance(transform.position,gold2.position) < distance)
 {
    
    GainPoints();
   }
   }
   
   function GainPoints()
   {
     Destroy(gold.gameObject);
     PointCode.points+= 5;
     blipsound.audio.Play();
   }



what should i do ? If there was 10 or 15 golds, i could put 15 different scripts which are specific for each gold . But there are 107 golds, so when i did it the FPS reduces to 2 , any suggestions to make that script work?

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 Inan-Evin · May 19, 2011 at 08:09 PM 0
Share

@macfanpro , thank you it works :)

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by ckfinite · May 19, 2011 at 07:55 PM

Basically, what you are doing is hard coding the distance check for all of the gold objects, drastically reducing flexibility. There is one good way to do what you want to do, and it is pretty simple.

First, you need to add a BoundingSphere to your gold prefab (Components->Physics->Bounding Sphere), set the sphere to the size you want, and check is trigger on the sphere. Then, add a new behavior to the gold object. The behavior should contain the following:

 function OnTriggerEnter(coll : Collider)
 {
     blipsound.audio.Play();
     PointCode.points+= 5;
     Destroy(gameObject);
 }
Comment
Add comment · 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

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

2 People are following this question.

avatar image avatar image

Related Questions

Non stopping point - counter 1 Answer

Point system, something wrong 1 Answer

points system with coins 3 Answers

How to make a character collect items? 4 Answers

Custom Sensor integration 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