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 Josenifftodd · Oct 20, 2013 at 05:45 AM · errorenemyspawnunityengine.object

No appropriate version of 'UnityEngine.Object.Instantiate'

I'm having a problem with this script:

 public var enemySpawnLimit : int;               // Sets the number of Enemys you wanna spawn at this location
 public var radiusmax: float;                    // The radius maximum.
 
 private var radiusx=0.0;                        // x co-ordinate
 private var radiusy=0.0;                        // y co-ordinate
 private var radiusz=0.0;                        // z co-ordinate
 
 
 //---------------------------------------------------------------------------------------//
 function Start () {
 
 //  for (var y = 0; y < enemySpawnLimit; y++) {                                             // If you wanna spawn the Enemys upwards, say for flying
 for (var x = 0; x < enemySpawnLimit; x++) {                                                 // this code is to cycle through spawning until X amount of enemys has arrived 
        
         
 radiusx=Random.Range(0.0,radiusmax);                                                     // Everytime A cube is spawned a it spawns at a random x,y,z location
 radiusy=Random.Range(0.0,5.0);
 radiusz=Random.Range(0.0,radiusmax); 
 
                                   
                                                                                                       
             Instantiate(enemy, Vector3 (radiusx, radiusy, radiusz), Quaternion.identity);       // the spawning script bit
         }
     }
 //}
 //---------------------------------------------------------------------------------------//
 
 //---------------------------------------------------------------------------------------//
 function Update () {
 
 }
 //---------------------------------------------------------------------------------------//


Not sure how to fix it. as I get this error.

 Assets/Scripts/enemy.js(22,24): BCE0023: No appropriate version of 'UnityEngine.Object.Instantiate' for the argument list '(System.Type, UnityEngine.Vector3, UnityEngine.Quaternion)' was found.
 

 
Comment
Add comment · Show 5
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 Benproductions1 · Oct 20, 2013 at 05:50 AM 0
Share

You need to pass Instantiate a Prefab not a Script/Type/Class

avatar image Josenifftodd · Oct 22, 2013 at 09:33 PM 0
Share

How would I do that Ben?

avatar image meat5000 ♦ · Oct 22, 2013 at 09:54 PM 0
Share

Basically, 'enemy' should be a GameObject or Prefab. I'm guessing the only reference to 'enemy' your script can find is enemy.js which is itself a script.

avatar image Josenifftodd · Oct 22, 2013 at 10:10 PM 0
Share

Yeah but when I name my model 'enemy' it doesn't work

avatar image Benproductions1 · Oct 24, 2013 at 09:26 AM 0
Share

You can't have two things with the same name. Take this for example:

 var enemy:enemy;

 function Start() {
     Instantiate(enemy);
 }

How is Unity supposed to find out which is which?

You either rename your script, or rename your variable. (You should give ALL your scripts capitols. It's just how things should be)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rutter · Oct 20, 2013 at 05:50 AM

This line:

 Instantiate(enemy, Vector3 (radiusx, radiusy, radiusz), Quaternion.identity);

Judging by the compiler error, enemy is the name of a script you wrote, not a variable in the code you posted.

Instantiate() is usually used to spawn a prefab instance. Perhaps you could create an inspector variable, then use that? There are plenty of tutorials around the net, but here's a quick example:

 public var enemyPrefab : GameObject;

 ...

 //in some function
 Instantiate(enemyPrefab, someVector, someRotation);
Comment
Add comment · Show 4 · 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 Josenifftodd · Oct 20, 2013 at 05:53 AM 0
Share

So adding that code will fix the problem?

avatar image rutter · Oct 20, 2013 at 06:05 AM 1
Share

It's more important to understand what the code does, even if it takes a bit longer. I suggest you read the link I posted.

avatar image Josenifftodd · Oct 20, 2013 at 08:10 PM 0
Share

i've looked through it all and I'm thinking it might not work because I haven't created a object I created an $$anonymous$$odel for the sprite and tried attaching to it. Would this be the problem? my mate was the one who wrote the code and it works fine on his PC just when he sent me it; it hasn't worked properly. I'm a little new to Unity I've only just managed to get my head around the HP/XP system and my character running etc lol

avatar image Benproductions1 · Oct 20, 2013 at 09:58 PM 0
Share

A "$$anonymous$$odel" in Unity is an object. It can act as a prefab

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

18 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

Related Questions

Enemy not spawning correctly 1 Answer

How to reduce the chances of a particular enemy spawning ? 3 Answers

Need help with enemy spawner 2 Answers

Spawning enemy mobs .......... Instantiate woe ? 2 Answers

Trying to write enemy spawn in JS. 2 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