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 /
This question was closed Oct 13, 2014 at 05:33 PM by thef1chesser for the following reason:

Other

avatar image
0
Question by thef1chesser · Oct 03, 2014 at 09:38 AM · c#prefabinstantiating

How to instantiate a prefab without showing it straight away

I am trying to create something similar as Mario Kart.

So when picking up the powerup (for let's say the green shield) I want to create it so the player can see he has the green shield. But I don't want to fire it yet.

My code:

 private void PickUp(PowerUp item)
 {
     if (Weapons == 1 && weapons[0] == null)
     {
         weapons[0] = item;
     }
 }

 // in Update
 if (Input.GetKeyDown(KeyCode.F))
     {
         if (Weapons == 1 && weapons[0] != null)
         {
             Instantiate(weapons[0], transform.forward, transform.rotation);
             weapons[0] = null;
         }
     }


As you can see I want to create it in a way all PowerUps can be instantiated and eventually karts might have multiple weapons.

What is the best way to approach this?

Do I need to Instantiate it beforehand and just not render it and put scripts on inactive?

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

  • Sort: 
avatar image
0

Answer by donaldleowjj · Oct 03, 2014 at 09:48 AM

Hmm...I'm not too sure whether this will work or not, but how about storing the power ups in a array?

Like this:

public GameObject[] PowerUps;

Then whenever you fire them just delete the powerup from the array or something. Hope it helps?

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 thef1chesser · Oct 03, 2014 at 09:54 AM 0
Share

Well the powerups that a kart has will be stored in an array, however people need to pick those up. So before people picking them up they have nothing, thus the array is empty.

It's not really about storing the powerups. It's how to get them in the array after they picked them up... Should I Instantiate there or later and if later how do I add it to the array here?

avatar image donaldleowjj · Oct 03, 2014 at 10:04 AM 0
Share

Ah I see. Weelll...I would Instantiate the objects on the course first, and when the player touches the object, then before deleting the object off the course, I do a (add to array) function to the power-ups array.

avatar image thef1chesser · Oct 03, 2014 at 10:22 AM 0
Share

Ye the only thing that might make that hard is that when a player hits a power up box on track it needs to randomly select a power up. This way players that have played the game will not have an advantage by knowing what power up is in what box.

Follow this Question

Answers Answers and Comments

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

Related Questions

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

spawning a prefab that have animation 1 Answer

Problem with prefab parent and children objects that need to be instantiated multiple times. 1 Answer

Script causing prefab export to have HUGE dependencies? 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