• 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 /
  • Help Room /
avatar image
-1
Question by Digitroni · Jan 10, 2018 at 04:38 AM · enemywaves

Create enemy with multiple waves/attacks?

Hello, I'm creating a 2D sidescroller and I'm extremely new to Unity. I'm wondering how I could make a large boss battle enemy, where it's a giant ear of corn that has multiple waves for attacks, each getting progressively more difficult as they go. I was wondering how I'd be able to pull that off? I'm very new to coding as a whole so please keep the answers simple and easy to understand, thanks!

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 KittenSnipes · Jan 10, 2018 at 09:20 AM

@Digitroni

If I am going to be honest it is a bit complex. First off you need some sort of health system to give both you and the boss health. The boss's max health should be much higher than the players obviously. Maybe you can have it so the corn loses some of its peaces each wave. So say there is 4 waves which I think is perfect for a boss. The first wave have some simple basic enemies that will give you items to help you face the boss's next wave. The second wave you should have an attack that does an increased amount of damage than any of his attacks so far. If you are left surviving then you once again get the same wave of simple mobs. The next two waves should be hard work. Make the mobs much harder and the final attack all of his kernels popping off. Now his angry and much faster but is also much weaker. So first off. Start with the simplest thing which is a script for health.

Here is an example:

 //The max health of the creature 
     //you are adding the script to.
     public int maxHealth = 100;
 
     //The health the creature currently has.
     private int currentHealth;
     void Start () {
         //On start set it's health to full health.
         currentHealth = maxHealth;
     }
 
     void TakeHealth(int DamageAmount)
     {
         //If you want this to do damage then 
         //set the damage value as a negative number.
         currentHealth += DamageAmount;
     }

Next you are going to need some sort of system of attacking. That is all up to your imagination. If you would like more help feel free to comment on my answer :D.

Comment
Add comment · Show 18 · 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 Digitroni · Jan 10, 2018 at 05:17 PM 0
Share

Thanks for replying, now do I need to make this a whole new script, or should I add it to my "Player" script? $$anonymous$$eep in mind that I'm using C#.

avatar image Buckslice Digitroni · Jan 10, 2018 at 06:32 PM 0
Share

Ya you probably want to have a couple scripts here. Obviously theres a bunch of different ways to do it but something like this might work.

  • Player (handles movement and attacks for player)

  • Boss (handles attacks and phases for boss)

  • Enemy script (handles movement and attacks for enemy

  • Health (manages health and maybe its display to UI as well, referenced by player, boss, enemy)

  • Projectile (handles projectile movement and damaging things when collided with)

  • Wave$$anonymous$$anager (communicates with boss and spawns waves of enemies at correct times)

avatar image Digitroni Buckslice · Jan 10, 2018 at 07:19 PM 0
Share

Is there a way that you could help me with this? I just now added the Health code, how would I make it so my player has health, and the enemy sprite has health as well. I also have no weapons or any way for the player to "hurt" the enemy sprite. I want to add a health bar GUI for both the player and enemy sprite. The player sprite will wield a sword-like weapon.

Show more comments
avatar image KittenSnipes Digitroni · Jan 10, 2018 at 09:41 PM 0
Share

@Digitroni

How does your player script look? Then we can decide.

avatar image Digitroni KittenSnipes · Jan 10, 2018 at 10:42 PM 0
Share

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class Player : $$anonymous$$onoBehaviour { public float maxSpeed = 3; public float speed = 50f; public float jumpPower = 150f; public float jumpSpeed = 8f; private Rigidbody2D rigidBody;

 public bool canjump;

 public bool grounded;

 private Rigidbody2D rb2d;
 private Animator anim;

 void Start () 
 {
     rb2d = gameObject.GetComponent<Rigidbody2D> ();    
     anim = gameObject.GetComponent<Animator> ();
 }

 void Update ()
 {
     {
         anim.SetBool ("Grounded", grounded);
         anim.SetFloat ("Speed", $$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")));

         if (Input.GetAxis ("Horizontal") < -0.1f)
             transform.localScale = new Vector3 (-1, 1, 1);

         if (Input.GetAxis ("Horizontal") > 0.1f)
             transform.localScale = new Vector3 (1, 1, 1);


         if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && grounded) {
             rb2d.AddForce (new Vector2 (0, jumpPower));
             Debug.Log("JU$$anonymous$$P" + "  -  Ground:" + grounded + "  CanJump:" + canjump + " ");
         }
     }
 }


 void OnCollisionEnter2D(Collision2D Other){
     if (Other.collider.gameObject.tag == "floor") {
         grounded = true;
         canjump = true;
         Debug.Log("COLL-Enter" + "  -  Ground:" + grounded + "  CanJmp:" + canjump + " ");
     }
 }

 void OnCollisionExit2D(Collision2D Other){
     if (Other.collider.gameObject.tag == "floor") {
         grounded = false;
         canjump = false;
         Debug.Log("COLL-Exit" + "  -  Ground:" + grounded + "  CanJmp:" + canjump + " ");
     }
 }

 void FixedUpdate ()
 {
     {

         float h = Input.GetAxis ("Horizontal");
         //$$anonymous$$oving the player
         rb2d.AddForce ((Vector2.right * speed) * h);

         //Limiting the speed of player
         if (rb2d.velocity.x > maxSpeed) {
             rb2d.velocity = new Vector2 (maxSpeed, rb2d.velocity.y);
         }

         if (rb2d.velocity.x < -maxSpeed) {
             rb2d.velocity = new Vector2 (-maxSpeed, rb2d.velocity.y);
         }
     }
 }


}

Show more comments
avatar image KittenSnipes · Jan 11, 2018 at 04:08 AM 0
Share

There is two ways. You can do it using Unity’s OnGui() function or you can manually create a Canvas with a ui health slider. Tell me which you would rather use

avatar image Digitroni KittenSnipes · Jan 11, 2018 at 03:22 PM 0
Share

I'd much rather create a canvas, as this makes it more customizable, right?

avatar image KittenSnipes · Jan 11, 2018 at 07:20 PM 0
Share

@Digitroni

Ok then make a canvas and create a slider under ui. Then all you have to do is set the sliders value to whatever the health is.

avatar image Digitroni KittenSnipes · Jan 12, 2018 at 03:19 AM 0
Share

Okay, I created a canvas, am I supposed to pair it to the $$anonymous$$ainCamera? And I also added the slider UI, and now theres just a random slider floating above my player in game.

avatar image KittenSnipes · Jan 12, 2018 at 04:31 AM 0
Share

@Digitroni

Well you will want to do:

 //Include this with your health class
 using UnityEngine.UI;
 
 //Add this to your variables
 public Slider healthSlider;
 
 void Start() {
     //Put this in to your void Start()
     healthSlider.value = health;
 }
 
 //Put it in to your //TakeDamage $$anonymous$$ethod
  void TakeDamage(int DamageAmount) {
     healthSlider.value = health;
 }
 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

75 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

Related Questions

Spawned enemy walk from right to left destroying turrets. 0 Answers

wave spawner difficulty increase 1 Answer

How to go on to next wave of enemies? 0 Answers

Time delay enemy respawn 3 Answers

Why is my player dying when defeating an enemy? 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