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 Yung-Hustla · Mar 07, 2011 at 08:39 PM · instantiatecloneontriggerstaygetbutton

OnTriggerStay Instantiate Problem (just want a single spawn, but there are multiple)

Hello People, im trying to spawn a collectable gameobjet every time my Character Stays within a Trigger and presses a button.

e.g. Move Player in front of an automat, press "E" and spawn a collectable ticket besides the automat. Thats the EXACT way i want it to be happen.

i got it completly working so far with this script:

var object: GameObject; var object2: GameObject;

function OnTriggerStay(Player : Collider) { if (Input.GetButtonUp("Action")){ Instantiate (object, Vector3(11,1,16), transform.rotation); Debug.Log("You can pick up your ticket right next to the vendor."); } else { if (Input.GetKeyUp("r")){ Instantiate (object2, Vector3(13.4,1,16), transform.rotation); Debug.Log("You can pick up your ticket right next to the vendor."); } } }

BUT every time i Press the "E" button to instantiate the ticket it instantiates MULTIPLE tickets. i just want a single one tho. Could anyone help me out with this pls ?

thx in advance :)

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 Eric5h5 · Mar 07, 2011 at 10:20 PM 0
Share

You don't need to write "solved" in the title; that's what accepting answers is for.

1 Reply

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

Answer by by0log1c · Mar 07, 2011 at 08:54 PM

Using OnTriggerStay is something I try to avoid as much as possible. Try setting a boolean according to whether your character is close or not to the machine. Something like this:

var object: GameObject; var object2: GameObject; var isNearby:boolean;

function Update(){ if(Input.GetButtonUp("Action") && isNearby){ Instantiate (object, Vector3(11,1,16), transform.rotation); Debug.Log("You can pick up your ticket right next to the vendor."); }else{ if(Input.GetKeyUp("r") && isNearby){ Instantiate (object2, Vector3(13.4,1,16), transform.rotation); Debug.Log("You can pick up your ticket right next to the vendor."); } } }

function OnTriggerEnter(Player : Collider) { isNearby = true; }

function OnTriggerExit(Player : Collider) { isNearby = false; }

Comment
Add comment · Show 3 · 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 Yung-Hustla · Mar 07, 2011 at 09:00 PM 0
Share

THAN$$anonymous$$ U SOOO $$anonymous$$UCH IT JUST WOR$$anonymous$$ED :) Thank you i tried to figure it out myself since 3 days XD

avatar image by0log1c · Mar 07, 2011 at 09:04 PM 0
Share

Glad I could help :) Not trying to pump up my reputation but the norm is usually to vote the helping answer up rather than just add 'Solved' in the thread name, so the website deals with it accordingly :)

avatar image Yung-Hustla · Mar 07, 2011 at 09:11 PM 0
Share

alright :) didnt know that thx for advice

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

No one has followed this question yet.

Related Questions

Cloning Problem Script 0 Answers

Cloned interactivecloth not acting like original interactivecloth. 0 Answers

Cloning Objects with Instantiate() - variables/references for added Components not stored? 3 Answers

Instantiated gameObjects can't find each other 0 Answers

How to Parent a Cloned Object to Another Cloned Object 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