• 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 post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by chicomeLIAP · Nov 27, 2012 at 07:03 AM · instantiateinput

script for instantiate object not working?

I have a script, it is simple... intantiating an object into the scene, but I haven't figured out why isn't working.

Can anyone help?

 var bala : Transform;
 
 if (Input.GetButtonDown("Fire1"))
 {
 var balaTiro = Instantiate (bala, gameObject.Find("bullet_SpawnPoint").transform.position, transform.rotation);
 //bala.rigidbody.AddForce(transform.forward * 1000);
 }
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 DeveshPandey · Nov 27, 2012 at 07:27 AM 0
Share

You have not mentioned here that what is problem, there is an error, warning or etc. Check the following points and let me know in details:
-ensure that bala is not null.
- make sure about the size of "bullet_SpawnPoint" is not big than bala, if it is bigger then bala there is chance to bala will be hidden by bullet_SpawnPoint.

1 Reply

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

Answer by harschell · Nov 27, 2012 at 11:55 AM

Did you attached the Script to any gameObject. If No then do Attach it to atleast something. Declare var bala : GameObject instead of var bala : Transform.

Try This Code::

 //var bala : Transform;
 
 var bala : GameObject;
 
 if (Input.GetButtonDown("Fire1"))
 {
 var balaTiro = Instantiate (bala, gameObject.Find("bullet_SpawnPoint").transform.position, Quaternion.identity); // You can also use transform.rotation
 
 }

Assign gameObject you want to instantiate in INSPECTOR to bala.

If Its HelpFull Do accept the Answer & give Thumbs Up to it :) @chicomeLIAP

Comment
Add comment · Show 1 · 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 chicomeLIAP · Nov 27, 2012 at 11:56 PM 0
Share

hehehehe ^^u , it came that it was missing function Update(){....}, didn't realize that, and it worked perfectly with both[quaternion & transform]

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

13 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

Related Questions

Checking if object intersects? 1 Answer

How to make sure only one GameObject is instantiated at a time. 3 Answers

Detect an Input.GetTouch in form of a Square/Quadrangle 1 Answer

How to disable mouse click detection in game when clicking exit menu button? 1 Answer

Object instantiates in the same spot (ScreenToWorldPoint) 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges