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 DolphinDudeOne · Jul 05, 2014 at 03:03 AM · enemyspawningcollison

Enemy Spawning

I am trying to get an enemy to spawn in 10 different locations using Vector3 or just anchoring the spawn to an invisible object. I need it so that when a collider, attached to the player, collides with the location the enemy will spawn. It will then chase the player for about a minute and will then disappear. There must only be one enemy at a time on the map. My only problem here is I'm not quite certain on how to code this. I've gone through the tutorials on the Unity site but none of them specify how to do this.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by JusticeAShearing · Jul 05, 2014 at 04:03 PM

Well, this playlist isn't from the Unity Site as far as I know, but he has enemies that spawn, so he could be of use to you.

https://www.youtube.com/playlist?list=PLB4DA4F8BDC3B82EE

This question speaks about spawning scripts, but isn't explicit about what to apply it to. Perhaps you know. If so, please tell me!

http://answers.unity3d.com/questions/418587/why-does-my-tree-script-not-work.html

Hopefully this helps you as much as it helped me.

Comment
Add comment · Show 2 · 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 DolphinDudeOne · Jul 06, 2014 at 12:57 AM 0
Share

I'm trying to get an enemy AI to spawn. So it will be the actually character that is going to chase the player throughout the game. The YouTube series didn't quite touch on the spawning I'm looking for but coincidently it answered a few questions I was going to have to figure out later like the player health!

avatar image JusticeAShearing · Jul 07, 2014 at 03:48 PM 0
Share

I have found more for you, out of the two hundred videos. Sorry if you checked them already and found them to be useless, but here they are:

This one deals with randomly spawning items, which should be convertible to enemies.

https://www.youtube.com/watch?v=EvF$$anonymous$$zj-_4A8&list=PLB4DA4F8BDC3B82EE∈dex=95

These two deal with AI.

https://www.youtube.com/watch?v=-fepHdO5jnE&list=PLB4DA4F8BDC3B82EE∈dex=127

https://www.youtube.com/watch?v=hOww54dF9Ac&list=PLB4DA4F8BDC3B82EE∈dex=129

avatar image
0

Answer by Stobby · Jul 06, 2014 at 10:11 AM

Hi!

You could code this by defining each spawn location as an empty game object with a simple triggered collider (capsule collider or anything else which suits your needs). Every spawn game object will have attached a script which will use the event OnTriggerEnter() to do two things:

  • Look if an Enemy exists

  • If the space is empy, spawn an enemy in the location.

In order to check for enemies the enemy prefab will have to be tagged as "Enemy".

I attach a pseudo-code example

 void OnTriggerEnter(Collider other)
     {
         
         //If somebody who's not the player is colliding, don't spawn
         if(other.tag != "Player")
            return;
 
         GameController handle2otherEnemies= GameObject.FindWithTag("Enemy");
 
         if(handle2otherEnemies!=null) //Ok, there is another enemy in game
            return;
         else //There is nobody
           Instantiate(Enemy,transform.position,transform.rotation);
 
       
     
         
     
     }

Just remember to:

  • create a public GameObject variable named Enemy linked to your Enemy prefab

  • Tag your Enemy prefab as "Enemy" (or whatever you like) and the Player as "Player"

Let me know if you need further assistance!

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 DolphinDudeOne · Jul 13, 2014 at 07:47 AM 0
Share

How should I create the Game Controller or should this script be the game controller?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Collison Sphere / Tagged Enemies only Near Player selection 0 Answers

How to handle entity management 1 Answer

My wave system isn't working 0 Answers

How to make my enemies spawn at spawn point, but not randomly? 1 Answer

Changing spawning position with C# 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