Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ajkidoo · Mar 29, 2018 at 04:30 PM · instantiatescript.prefabs

Something wrong with my project

Hi, I need help with my project because something went wrong and I dont know why. I wanted one of my scripts to choose one of 2 ''paths'' i created for objects called "Tiles"

 public Transform Tile1;
     public Transform Tile2;
     public Transform Tile3;
 
 
 
 
     void Start () 
     {
         if (Random.value <= 0.5) {
             Tile1.position = new Vector3 (3, 2.136f, -4.413f);
             Tile2.position = new Vector3 (3.481f, 2.136f, -3.697f);
             Tile3.position = new Vector3 (3.979f, 2.136f, -2.976f); 
         }
 
         else
         {
             Tile1.position = new Vector3 (3.482f, 2.136f, -4.413f);
             Tile2.position = new Vector3 (2.838f, 2.136f, -3.697f);
             Tile3.position = new Vector3 (4.319f, 2.136f, -4.42f); 
         }
     }

and then replace those objects with one of three prefabs

(that script is attached to each "Tile" object)

     public GameObject myPrefab1;
     public GameObject myPrefab2;
     public GameObject myPrefab3;
 
     // Use this for initialization
     void Start () {
         if (Random.value <= 0.33) {
             Instantiate (myPrefab1, transform.position, Quaternion.identity);
         }
         else if (Random.value <= 0.33) {
             Instantiate (myPrefab2, transform.position, Quaternion.identity);
         }
         else {
             Instantiate (myPrefab3, transform.position, Quaternion.identity);
         }
     }

I wanted to make a simple generator-like thing which i can easily control. The problem is when i run my game everything works correctly except when one of those objects become myPrefab1. It appears in game but it has different coordinates than "Tile" object. I dunno what i messed up. Can anyone tell me whats wrong ? Thanks in advance. (Sorry, english isn't my native language, so it can hurt your eyes :~)

Comment
Add comment
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

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

100 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

Related Questions

How to instantiate a prefab declared in one script, from another script 2 Answers

How can you make a Instanciate prefab follow a scene object? 1 Answer

Instantiating Prefabs from a MonoBehaviour-derived class using an array -> compiling but not rendering [SOLVED] 0 Answers

Tile game instatiation 1 Answer

Different prefab getting instantiated? 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