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 _Nemesis_ · Jan 19, 2014 at 11:15 AM · instantiateprefabsclonecapsule

I cannot see my cloned prefabs.

Hello!!

I'm trying to clone one of my prefabs (capsule named X) when I press down my left button mouse. My capsule is cloned each time I press the button and I know this because I can see X(cloned) in the hierarchy, but there aren't any capsule in the "map".

Here Is my code:

 var X : Transform;
 
 function Start () {
    
 }
 
 function Update(){
     
     Debug.Log(Input.GetMouseButtonDown(0));
     if (Input.GetMouseButtonDown(0) == true){
         Instantiate(X,Vector3 (Input.mousePosition.x,0,Input.mousePosition.z), 
             Quaternion.identity); //Creating clones
         Debug.Log(Input.mousePosition); 
    }
 }

How can I see each capsule? I've read the unity tutorials of instantiate but I don't know if I need to add anything else.

thank you for your answers^^

Comment
Add comment · Show 5
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 Benproductions1 · Jan 19, 2014 at 12:03 PM 0
Share

Input.mousePosition is a screen position, which ranges from 0, 0 all the way to length and height (in pixels) of your screen.

For instance, if the mouse is in the middle of my 1080p screen, then the mouse position will be: 960, 540, which is very far away from the origin.

Are you sure you want to instantiate objects using screen positions?

avatar image _Nemesis_ · Jan 19, 2014 at 12:10 PM 0
Share

I'm a bit noob (sure you realise that xD) so... do you have any other idea to instantiate an object in te position of my mouse (when I press left button)? In fact I'm trying to do that and I thought that was the easier way.

avatar image Benproductions1 · Jan 19, 2014 at 12:12 PM 0
Share

Thats a different question and has already been answered many times before. There are many tutorials out there that can help you.

avatar image joedartjr · Jan 20, 2014 at 12:38 AM 0
Share

You could tie the Instantiate script into an object parenting the camera, and use the camera's look position to call the instantiate; but that would depend on what type of camera you were using; First-Person, Third-Person, Isometric. You could also Draw a Raycast from the camera or another game object (maybe one attached to a character or movable object) that would allowed you to instantiate objects at the point the raycast collides with another object, or the ground, or a designated layer... Again, it all depends on how you want to implement the instantiated object into the game world. $$anonymous$$ouse position is a bad route to go though.

avatar image robertbu · Jan 20, 2014 at 01:48 AM 0
Share

You need to figure out a distance in front of your camera you want to instantiate. Then you could so this (10 units in front of the camera):

     if (Input.Get$$anonymous$$ouseButtonDown(0)){
          var pos = Input.mousePosition;
         pos.z = 10.0;
         pos = Camera.main.ScreenToWorldPoint(pos);
         Instantiate(X,pos, Quaternion.identity); //Creating clones
    }

0 Replies

· Add your reply
  • Sort: 

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

20 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

Related Questions

Prefab clones behaviour 0 Answers

Instantiate Reference Problem 1 Answer

i attach the prefab, but when i hit play, its not the prefab anymore 0 Answers

Different prefab getting instantiated? 1 Answer

Object reference not set to an instance of an 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