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 Novrick · Oct 18, 2011 at 08:15 AM · instantiateprefabinput

trouble with instantiate

I'm trying to make a game that you can spawn objects with simply pressing the number keys.

and it's working great so far, but for some reason I can't spawn the third object

can someone help me?

here's the code:

 using UnityEngine;
 using System.Collections;
 
 public class spawnscript : MonoBehaviour {
     
 
 public GameObject cubeprefab;
 public GameObject rectangleprefab;
 public GameObject stairprefab;
 public GameObject spawncube;
 
 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
     
     
             
     if(Input.GetKeyDown("1"))
     {
         
         if(idea.Instance.shadow1 == true)
         {
         
     //Vector3 position = new Vector3(camera.transform.position.x + 2, camera.transform.position.y);
     
     Instantiate(cubeprefab, transform.position, transform.rotation);
     //Physics.IgnoreCollision(cubeprefab.collider, spawncube.collider);
         }
         
     }
     
     
     if(Input.GetKeyDown("2"))
     {
     
     if(idea.Instance.shadow2 == true)
         {
         
     Instantiate(rectangleprefab, transform.position, transform.rotation);    
             
         }
         
         
         
     if(Input.GetKeyDown("3"))
         {
         
             //if(idea.Instance.shadow3 == true)
             //{
                 
             Instantiate(stairprefab, transform.position, transform.rotation);
                 
             //}
             
             
             
         }
         
         
     }
     
     
     
     
 
 }

}

Comment
Add comment · Show 4
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 syclamoth · Oct 18, 2011 at 08:16 AM 0
Share

Getting any error messages? This looks fine to me.

avatar image Novrick · Oct 18, 2011 at 08:22 AM 0
Share

well no, there are no error messages. the stairprefab just won't spawn into the scene =S

avatar image Uniquesone · Oct 18, 2011 at 08:33 AM 0
Share

Insert a Debug.Log("$$anonymous$$ey 3 pressed") into if(Input.Get$$anonymous$$eyDown("3"))

avatar image Proportion · Oct 18, 2011 at 08:39 AM 0
Share

try swapping Instantiate(stairprefab, transform.position, transform.rotation); with Instantiate(rectangleprefab, transform.position, transform.rotation); just to see if its the get key down or if its the instantiated object that is the problem. eg if u swap them and pressing 2 makes the stair prefab work, the getkeydown is stuffing up, but if u press 3 and the rectangle works its the stair prefab

1 Reply

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

Answer by Uniquesone · Oct 18, 2011 at 08:40 AM

You forgot an } after the instantiate of key input 2!

Remember to remove an } at the end of the file, or you would get an error =)

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 Novrick · Oct 18, 2011 at 08:56 AM 0
Share

...it works now. Oh god, how clumsy of me x'D

but thanks man! : D

avatar image Uniquesone · Oct 18, 2011 at 09:03 AM 0
Share

You're welcome =)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Instantiating prefab of object like it was in the scene 0 Answers

Instantiating prefabs: "The object of type GameObject has been destroyed". 1 Answer

How can I determine an object of prefab's size (for positioning when instantiating them) 2 Answers

Instantiate prefab once help C# 1 Answer

Missing Material in AssetBundle Prefab 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