• 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 lorainiscool · Mar 16, 2014 at 06:54 PM · colliderobjectbulletpickup

Pickup Bullets

Hi, i am making a shooting game where there are bullets scattered on the ground. the first person controller has to pick them up and shoot the bird. I cant seem to pick up the bullets. Also, the first person controller passes right through the bullets instead of picking em up. I am pasting my code here. Someone please help ASAP :s Bullet.cs: using UnityEngine; using System.Collections; public class Bullet : MonoBehaviour { public GameObject bullet; public static int count = 0; //public AudioClip beep; // Use this for initialization void Start () { count = 0; } // Update is called once per frame void Update () { } void Pickup() { count++; } void OnTriggerEnter (Collider col) { if(collider.gameObject.tag == "Player") { //AudioSource.PlayClipAtPoint(beep, transform.position); collider.gameObject.SendMessage ("Pickup"); Destroy(gameObject); } } }

Inventory.cs enter code hereusing UnityEngine; using System.Collections;

 public class Inventory : MonoBehaviour {
     public static int count = 0;
     
     public AudioClip beep;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void Pickup()
     {        
         AudioSource.PlayClipAtPoint (beep, transform.position); //will play sound at a specific position
         count++;
     }
 }
 
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

1 Reply

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

Answer by sami1592 · Mar 16, 2014 at 07:16 PM

when ever the player collides with the bullet you want to call the function PickUp() in the Inventory.cs right?

when ever a collision occurs with the player, the pickup function of the collided object is called. So in order this to work you have to attach Inventory.cs to the player. My guess is you haven't don't it, so the pickUp function is called in the Player's scripts bt it cant find any function named PickUp in the controllers script

let us know if the problem is solved

oh one other thing, in the first script there will be a correction

 void OnTriggerEnter (Collider col)
 {
     // here 
     if(col.gameObject.tag == "Player")
     {
        //AudioSource.PlayClipAtPoint(beep, transform.position);
        collider.gameObject.SendMessage ("Pickup");
        Destroy(gameObject);
     }
 }
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 lorainiscool · Mar 16, 2014 at 07:28 PM 0
Share

yeah it worked.. but what is the correction? :/

avatar image sami1592 · Mar 17, 2014 at 06:32 AM 0
Share
  1. Attaching the Script to the player

  2. look at the code, in line 3-4

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Ammo Pickup 0 Answers

Adding force to a bullet as it hits object? 2 Answers

How to pickup objects with Kinect (using colliders) 0 Answers

Spawn an object? 2 Answers

Can someone help me with the initialize and pick up script, please? 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