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 NoodleCup · Jul 02, 2019 at 12:51 AM · arrayvector3empty game object

Using Vector3[] to store vector3 of objects,

Im using emptygameobjects as positions to instantiate objects as their spawn positions. Is there a reason I cannot drag and drop an emptygameobject in the Inspector to the Vector3[] Array? since I assume im using this array wrong. How do I pass a Vector3 of a gameobject to my vector3 array list? thanks in advance, code I wrote is below.

{ public Vector3[] spawnPoints; public GameObject[] obstacles; public float spawnRadius;

 private void Start()
 {
 
     //int spawnPointIndex = Random.Range(0, spawnPoints.Length);
     //int obstaclesIndex = Random.Range(0, obstacles.Length);
     int howmanytospawn = Random.Range(0, 10);

     for (int i = 0; i < howmanytospawn; i++)
     {
         int spawnPointIndex = Random.Range(0, spawnPoints.Length);
         int obstaclesIndex = Random.Range(0, obstacles.Length);

         if (!Physics.CheckSphere(spawnPoints[spawnPointIndex],spawnRadius))
         Instantiate(obstacles[obstaclesIndex], spawnPoints[spawnPointIndex], Quaternion.identity);
     }
 }


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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by NoodleCup · Jul 02, 2019 at 02:21 AM

To answer this question to anyone that comes googling after me, I was trying to use vector3 to store positions of items. after much googling and understanding my ideocracy. You should use transforms to store positions of objects. Instead of using vector3 spawnPositions I used a transform spawnPositions and in my instantiate area of the code I had to add transform.position to the location part of the function.

so

public Transform[] spawnPoints;

Instantiate(obstacles[obstaclesIndex], spawnPoints[spawnPointIndex].transform.position, Quaternion.identity);

fixed my understanding of vector3s and transforms then I was easily able to differentiate the use of each. cant use vector3 when you're looking for a world pos. goodluck.

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 Optrix · Jul 02, 2019 at 03:33 AM 0
Share

Just to clarify (for any future readers) - a Vector3 can be used to store the position of an item, but it only stores the position at that moment in time. Useful for backing up a previous position etc.

If you want to be able to get an up-to-date item position, then yes - Transform is certainly the class you need, and good work figuring it out.

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

147 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

Related Questions

instantiate problem help? 1 Answer

What is the order/connection of array elements in mesh.vertices? 2 Answers

c# : Accessing Struct variables inside an Array 1 Answer

Read variable from txt to Vector3 1 Answer

Vector3 Position returns 0 when applied to GameObject 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