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 GhostDre · Dec 11, 2013 at 12:10 AM · pickupflashflashlightitem pickup

Pick up item code is not working

Hi everyone I made the 2 codes but it seems like they dont work. I made a PickUp code for my player and a PickUpFlash code in my flashlight. If anyone can help out by noticing whats wrong please let me know.

Here is the the code I put into the Character:

 using UnityEngine;
 using System.Collections;
 
 public class PickUp : MonoBehaviour 
 {
     public static GameObject WalkedOverObject;
 
     
     void OnTriggerEnter(Collider other) {
         WalkedOverObject = other.gameObject;
     }
     void OnTriggerExit(Collider other) {
         if (WalkedOverObject == this.gameObject) WalkedOverObject = null;
     }
 }

Here is the the code I put into the Flashlight:

 using UnityEngine;
 using System.Collections;

 public class PickUpFlash : MonoBehaviour {

     void Update () {
     
         if(Input.GetKeyDown(KeyCode.E))
         {
             if (PickUp.WalkedOverObject) Destroy(PickUp.WalkedOverObject);
         }
 
     }
 }
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 PictonicStudio · Dec 11, 2013 at 01:23 AM 0
Share

I'm not understanding your logic. You just want to pick up a flashlight?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Statement · Dec 11, 2013 at 01:49 AM

I have no idea what is wrong, but here's a checklist of some sorts:

  • The object you must trigger with, needs a trigger collider.

  • The player needs a character controller or a rigidbody with a collider.

  • The collision layers must be set so they trigger each other. (On by default)

  • The game objects and colliders/triggers needs to be enabled.

  • The collider and trigger must actually touch (maybe it's too low/too high away from player?)

  • The scripts must be attached to the correct objects in the scene.

And I probably missed a few corner cases. But if all else is set up, your script seems to do the following:

  • If the Character enters any kind of trigger, remember that as the WalkedOverObject.

  • If the Character leaves itself (out of body experience? :-)), forget WalkedOverObject.

  • If "E" is pressed, and you haven't WalkedOverObject, nothing happens.

  • If "E" is pressed, and you have WalkedOverObject, the object is Destroyed (which can be any trigger).

  • don't know if it's supposed to be a Flashlight or an Area nor how Destroying it would resemble the behaviour of a flashlight.*

I can tell you one thing that this will do. It will not turn a single light on, based on this information alone. You are only destroying whatever you've bumped into when you press "E".

Maybe you can start by telling if any of this behaviour is wrong and what part of this you need help with?

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 Karaka · Oct 06, 2015 at 01:28 AM

I know this is two years too late but here is my answer. When the Walked over object is walked over put it into an inventory script.

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

19 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

Related Questions

Trigger event from ground and activate the Object-child in the Camera 1 Answer

Very simple picking up items script? 2 Answers

FlashLight Fixes Please?? 1 Answer

How to use PlayerPrefs to stop an item from reappearing when you return to the level 2 Answers

Flashlight pickup, battery etc 3 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