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
1
Question by N-Dev Games · Mar 07, 2012 at 03:13 AM · instantiatespawn

Simple and Quick Fix PickUp script

Guys, I am having an issue with a simple script. To make it quick, I have this script attached to my player. I have a couple spheres tagged coin. I collect them and it adds points to the score and destroys the sphere. That part is fine.

Recently I decided I did not want the sphere to destroy. I now wanted it to be spawned to a holding place for the spheres(Coins) in the level. So, I created an empty GameObject and used it as my spawn point. So now when I collect the coins, they all go to that location. Fine.

The problem is that I want them to collect inside the holding area realistically. Imagine a glass and you you drop marbles in it. So I set the spawn point above the container and added a rigid body to the spheres. The spheres now automatically fall through the plane. I tried making the colliders all primitive and tried making the plane a mesh collider and the spheres primitive but its a no go. They just fall through the floor. Where am I going wrong. And also is it possible that some one can give me hints as to the best way to approach using an array to keep track of the amount of spheres in the container? something like the container has 5 boxes then I can no longer collect any boxes.

     var score = 0;
 var scoreText = "Score: 0";
 var track : AudioClip;
  
 var packTruck : Transform;
  
 function OnTriggerEnter( other : Collider ) {
     Debug.Log("OnTriggerEnter() was called");
     if (other.tag == "Coin") {
         Debug.Log("Other object is a coin");
         score += 5;
         scoreText = "Score: " + score;
         Debug.Log("Score is now " + score);
         audio.Play();
         other.transform.position=packTruck.transform.position;
     }
 }
  
 function OnGUI () {
      GUI.Label (Rect (10, 10, 100, 20), scoreText);

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 N-Dev Games · Mar 07, 2012 at 01:17 PM 0
Share

So I declare the trigger state to true initially and then once it is collected set it to false and add a rigidbody component within the script? But how would I add the component if the script is attached to the player and not the coin? also am I going about the moving the coin to the container, because the container will be attached to a moving object?

avatar image N-Dev Games · Mar 08, 2012 at 01:11 PM 0
Share

Would it be easier if I just destroy the object and spawn a prefab to the spawn location? If so how would I go about doing that.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by deepthinker · Mar 07, 2012 at 12:15 PM

Put a box collider on the plane instead of a mesh collider.

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
avatar image
0

Answer by aldonaletto · Mar 07, 2012 at 12:29 PM

Who's the trigger? The coins? If so, they will fall through any collider if a rigidbody is added. You can add a rigidbody only when placing the coin in the holder, and set the collider.isTrigger property to false to make it a regular collider.

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

6 People are following this question.

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

Related Questions

Spawn from array 2 Answers

Instantiating prefab at child (spawnlocations are arrays) 2 Answers

instanstiate Spawns more then one objec 0 Answers

Network.Instantiate players at each spawnpoint? Don't use the same spawnpoint? 1 Answer

Instantiated enemy looks at player 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