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 aafasfasdf · Feb 26, 2015 at 08:09 PM · errorgameobjectinstantiatetransformcompilation

Weird compilation error regarding Instantiate

So this is what I get: CompilationErrorsException: script(1,12): BCE0023: Boo.Lang.Compiler.CompilerError: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(UnityEngine.GameObject, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.

The manual says that it should be a GameObject followed by Vector3 and Quaternion, but it doesn't work for some reason. I've never had that error before.

Here's the line:

 eval("Instantiate(enemy"+randomEnemyType.ToString()+",enemypos"+(randomEnemyPos+1).ToString()+".position,Quaternion.identity);");

Here's how the function looks like with the variables:

 Instantiate(enemy1,enemypos1.position,Quaternion.identity);

There are 4 enemy types with a prefab for each one (GameObject) and 16 possible enemy spawn points (Transform). Both are random so it could be enemy3 and enemypos13.position, etc...

So can someone explain why this doesn't work or better yet - give me a solution to the problem?

Comment
Add comment · Show 2
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 aafasfasdf · Feb 26, 2015 at 08:32 PM 0
Share

For example, there are 4 variables for enemy types - enemy1, enemy2, enemy3, enemy4. The script generates a random number from 1 to 4 which deter$$anonymous$$es which enemy type I'm going to use. I couldn't think of another way. Even if I use ifs, there are still the positions (16 of them). That equals 64 possible position/enemy combinations.

avatar image tanoshimi · Feb 27, 2015 at 11:46 AM 0
Share

The correct way to do that is to make an array with [enemy1, enemy2, enemy3, enemy4] and choose a random element from the array. Don't pick a random number, append it to a string, and then try to evaluate that as an object...

http://unity3d.com/learn/tutorials/modules/beginner/scripting/arrays

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

NaN exception when spawning soldiers 1 Answer

How to make random alien fire and not all of them at once.. 2 Answers

How to instanciate transform to element of a list?,How Get Transform of a instanciated Prefap 3 Answers

problems parenting a gameObject to another upon instantiating when same name exists 1 Answer

Set parent of instantiated object. 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