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 FusionSausage · Sep 21, 2013 at 06:02 PM · c#instantiateprefabobjectsmultiple

Multiple object prefab instantiates too far down

Hi. I have a prefab with 12 cubes that all have box colliders and the prefab also have a box collider. I also have a script which instantiates objects where the mouse-click happened. Now, if I instantiates the first prefab which is the one with the 12 cubes it instantiates it far down in the terrain, although the terrain have a terrain collider. When I pick my 2nd or 3d prefab which is only has one object it works. It instantiates on the terrain. I've also checked in the log if it's something wrong with my mouse input, but it's the same for all objects.

Script:

 using UnityEngine;
 using System.Collections;
 
 
 public class placeObject : MonoBehaviour {
     
     public Player player;
     
     public Transform Object1;
     public Transform Object2;
     public Transform Object3;
     
     public Camera Eye;
     
     public int chosenObject = 1;
     public int ChosenObject { get{ return chosenObject; } set{ chosenObject=value; } }
     
     // Use this for initialization
     void Start () {
         //GameObject Eye = GameObject.Find("Camera");
     }
     
     // Update is called once per frame
     void Update () {
         
     if(Input.GetKeyDown("1")){
         Debug.Log("Key 1 pressed, outputs small village");
         chosenObject = 1;
         }
         
     else if(Input.GetKeyDown("2")){
         Debug.Log("Key 2 pressed, outputs Cylinder");
         chosenObject = 2;
         }
         
     else if(Input.GetKeyDown("3")){
         Debug.Log("Key 3 pressed, outputs Sphere");
         chosenObject = 3;
         }
     }
     
     void OnMouseUp () 
 
     {
 
     Ray ray = Eye.camera.ScreenPointToRay (Input.mousePosition); 
 
        RaycastHit hit; 
 
     if (Physics.Raycast (ray, out hit, 2000)) 
 
     { 
         if(chosenObject == 1){
                 if(player.Money > 100){
                     player.Money -= 100;
                     //player.Population += 30;
                     Debug.Log("Chosen object is 1 and will output a small village. Merry christmas!");
                     Debug.Log (hit.point);
                     Instantiate(Object1, hit.point, Quaternion.identity); 
                 }
                 else {
                     Debug.Log ("Too poor");
                 }
         }
         else if(chosenObject == 2){
                 if(player.Money > 200){
                     player.Money -= 200;
                     Debug.Log("Chosen object is 2 and will output a cylinder. Merry christmas!");
                     Debug.Log (hit.point);
                     Instantiate(Object2, hit.point, Quaternion.identity); 
                 }
                 else {
                     Debug.Log ("Too poor");
                 }
         }
         else if(chosenObject == 3){
                 if(player.Money > 300){
                     player.Money -= 300;
                     Debug.Log("Chosen object is 3 and will output a sphere. Merry christmas!");
                     Instantiate(Object3, hit.point, Quaternion.identity); 
                 }
                 else {
                     Debug.Log ("Too poor");
                 }
         }
         else {
             
         }
         Debug.Log("Prefab cloned!");
     }
 }
 }


How do I make my prefab instantiate on top of the terrain instead of under it? It looks like it is a evenly space between because if I instantiate it a little bit under it instantiates a bit more down than it was on the higher point.

Thank you.

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 FusionSausage · Sep 22, 2013 at 07:56 AM 0
Share

None knows?

avatar image Hoeloe · Sep 22, 2013 at 09:12 AM 0
Share

Is the output from the logging of "hit.point" correct?

avatar image FusionSausage · Sep 22, 2013 at 11:18 AM 0
Share

It outputs the same coords as the one that works, so yes.

avatar image Hoeloe · Sep 22, 2013 at 02:07 PM 0
Share

It which case, it sounds like the centre point of your prefab is off. Drag the prefab onto the stage - where does the movement control appear?

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

16 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

Related Questions

Instantiate an array of prefabs? 0 Answers

Changing texture on prefab at runtime (c#) 1 Answer

Why does this prefab trigger all instances to action? C# 1 Answer

Spawning a prefab at another object's location 3 Answers

Instantiate 3 guiTextures at the same 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