• 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 Lustucrue · May 29, 2019 at 05:38 PM · raycastinstantiateprefab-instance

How instantiate only one prefab at different spawn place ?

Hello, Fristly sorry for my bad english :/

So I want instantiate one prefab for different spawn place but only 2 times. But spawn must run when I click on a specific model.alt text

capture.png (349.5 kB)
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 highpockets · May 29, 2019 at 10:03 PM 0
Share

Ok, not to sure what you mean by spawn must run when I click on a specific model, but I’m assu$$anonymous$$g you need the prefab to react to a click on it by running?? Anyhow, you can spawn a prefab at a different spawn position 2 times by using Instantiate(prefab, worldPositionYouWant, rotationYouWant, transformsParent); 2 times, but with 2 different positions.


Thereafter you can use the mousePosition, which is in screen space and needs to be turned into world space with Camera.ScreenToWorldPoint() for example, and you can raycast to see if you hit one of your prefabs and if so, you can make it run. Not sure if that was the idea, but that is what I understood from your question.

Show more comments
avatar image Lustucrue · Jun 04, 2019 at 11:57 AM 0
Share

Thank you !! I have an other problem... Spawn running perfectly but my script is overload : I have 90 prefab's initialization 1 group -> 6 sphere there are 15 groups When value in a slider change(increase or decrease) one groupe appear or disappear

public class CameraDetection : $$anonymous$$onoBehaviour {

 public SpawnOne[] spawn;
 public double[] nmb = new double[2];
 private int i = 0;

 // Update is called once per frame
 public void Detection () {
     Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
     RaycastHit hit;
         if (Input.Get$$anonymous$$ouseButtonDown (0)) {

             if (Physics.Raycast (ray, out hit) && i < 2) {
             
             if (hit.transform.tag == "sphere1") {
                     spawn [0].Spawn ();
                     nmb [i] = -1.0;
                     i++;

                 } else if (hit.transform.tag == "sphere2") {
                 
                     spawn [1].Spawn ();
                     nmb [i] = -1.1;
                     i++;
                 } else if (hit.transform.tag == "sphere3") {
                 
                     spawn [2].Spawn ();
                     nmb [i] = -1.2;
                     i++;
                 } else if (hit.transform.tag == "sphere4") {
                 
                     spawn [3].Spawn ();
                     nmb [i] = -1.3;
                     i++;
                 } else if (hit.transform.tag == "sphere5") {
                 
                     spawn [4].Spawn ();
                     nmb [i] = -1.4;
                     i++;
                 } else if (hit.transform.tag == "sphere6") {
                 
                     spawn [5].Spawn ();
                     nmb [i] = -1.5;
                     i++;
                 }else if (hit.transform.tag == "sphere1.1") {

                     spawn [6].Spawn ();
                     nmb [i] = -1.1;
                     i++;
                 }
                 else if (hit.transform.tag == "sphere1.2") {
                 
                     spawn [7].Spawn ();
                     nmb [i] = -1.1;
                     i++;
                 } else if (hit.transform.tag == "sphere1.3") {
                 
                     spawn [8].Spawn ();
                     nmb [i] = -1.2;
                     i++;
                 } else if (hit.transform.tag == "sphere1.4") {
                 
                     spawn [9].Spawn ();
                     nmb [i] = -1.3;
                     i++;
                 } else if (hit.transform.tag == "sphere1.5") {
                 
                     spawn [10].Spawn ();
                     nmb [i] = -1.4;
                     i++;
                 } else if (hit.transform.tag == "sphere1.6") {
                 
                     spawn [11].Spawn ();
                     nmb [i] = -1.5;
                         i++;
                 } else if (hit.transform.tag == "sphere2.1") {
                 
                     spawn [12].Spawn ();
                     nmb [i] = -1.1;
                     i++;
                 } else if (hit.transform.tag == "sphere2.2") {
                     
                     spawn [13].Spawn ();
                     nmb [i] = -1.1;
                     i++;
                 } else if (hit.transform.tag == "sphere2.3") {
                 
                     spawn [14].Spawn ();
                     nmb [i] = -1.2;
                     i++;
                 } else if (hit.transform.tag == "sphere2.4") {
                 
                     spawn [15].Spawn ();
                     nmb [i] = -1.3;
                     i++;
                 } else if (hit.transform.tag == "sphere2.5") {
                 
                     spawn [16].Spawn ();
                     nmb [i] = -1.4;
                     i++;
                 } else if (hit.transform.tag == "sphere2.6") {
                 
                     spawn [17].Spawn ();
                     nmb [i] = -1.5;
                     i++;
             } 
         }
     }
 }

}

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Related Questions

Prefabs wont instantiate? 2 Answers

Instanciate prefab responsively 1 Answer

prefab spawning with variable delay 0 Answers

The Weirdest Bug Ever: GameObject Transform Appears in Editor to Be in One Spot but Instantiates and Registers in Another 2 Answers

Particle Instantiation problem. 0 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