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 /
  • Help Room /
avatar image
0
Question by xyHeat · Jan 17, 2016 at 10:19 AM · enemylife

Ennemy don't lose life [C#]

Hello Everybody ! I'm creating a little game where ennemies goes to a castle and you are a tower who defend the castle. But I have a problem... When my ennemy is touching the castle, the castle lose 1 life but when my bullet touch the ennemy, he don't lose life... I created a empty child for the collider of my ennemy, and one for my bullet but it doesn't work.... This is my ennemy script

using UnityEngine; using System.Collections;

public class Ennemy : MonoBehaviour { private NavMeshAgent agent; public static int lvl = 1; public static double Damage; public static double Vies = 10;

 void Start () {
     lvl = 1;
     agent = GetComponent<NavMeshAgent>();     //déplacement
     //NavMeshPath chemin = new NavMeshPath();
     agent.destination = GameObject.Find ("Castle").transform.position;  //sa destination est la postition de "castle"
 }
 

 void Update () {
     Damage = GameManager.Damage;

     Vies = 10 + (lvl * 3);
     //////////////////////////////////////////////////////////// VIES PAR LEVEL
     if (GameManager.score >= 250){
         lvl = 2;
     }
     if (GameManager.score >= 500){
         lvl = 3;
     }
     if (GameManager.score >= 750){
         lvl = 4;
     }
     if (GameManager.score >= 1000){
         lvl = 5;
     }
     if (GameManager.score >= 2250){
         lvl = 6;
     }
     if (GameManager.score >= 2500){
         lvl = 7;
     }
     if (GameManager.score >= 2750){
         lvl = 8;
     }
     if (GameManager.score >= 2000){
         lvl = 9;
     }
     if (GameManager.score >= 2250){
         lvl = 10;
     }
     if (GameManager.score >= 2500){
         lvl = 11;
     }
     if (GameManager.score >= 2750){
         lvl = 12;
     }
     if (GameManager.score >= 3000){
         lvl = 13;
     }
     if (GameManager.score >= 3250){
         lvl = 14;
     }
     if (GameManager.score >= 3500){
         lvl = 15;
     }
     if (GameManager.score >= 3750){
         lvl = 16;
     }
     if (GameManager.score >= 4000){
         lvl = 17;
     }
     if (GameManager.score >= 4250){
         lvl = 18;
     }
     if (GameManager.score >= 4500){
         lvl = 19;
     }
     if (GameManager.score >= 4750){
         lvl = 20;
     }
     if (GameManager.score >= 5000){
         lvl = 21;
     }
     if (GameManager.score >= 5250){
         lvl = 22;
     }
     if (GameManager.score >= 5500){
         lvl = 23;
     }
     if (GameManager.score >= 5750){
         lvl = 24;
     }
     if (GameManager.score >= 5000){
         lvl = 25;
     }
     if (GameManager.score >= 5250){
         lvl = 26;
     }
     if (GameManager.score >= 5500){
         lvl = 27;
     }
     if (GameManager.score >= 5750){
         lvl = 28;
     }
             
     //////////////////////////////////////////////////////////// VIES PAR LEVEL


     if (Vies <= 0) {
         Destroy(this.gameObject);
         GameManager.argent += 1;
         GameManager.score += 5;
     }
 }

 void OnTriggerEnter (Collider col){
     if (col.gameObject.name == "Castle") {
         TextVie.vie--;
         Destroy (this.gameObject);
     } 
     if (col.gameObject.name == "Bullet(Clone)") {            
         Vies -= Damage;
         Destroy (col.gameObject);
     }
 }

}

Thank you very much, that reading my post, i hope some one can help me.... Bye, xyHeat

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
Best Answer

Answer by SneakySquid · Jan 17, 2016 at 10:31 AM

From what I can tell, you are losing health/Vies, but in your Update function, you have

Vies = 10 + (lvl * 3);

This keeps resetting Vies to this value, so you never lose any health/Vies

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 xyHeat · Jan 17, 2016 at 10:34 AM 0
Share

Thank you a lot ! I didn't see that ...

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

37 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

Related Questions

How to make an enemy 2d chasing player? 2 Answers

I need the Nav Mesh Stop , I need the Animation to Play Javascript 0 Answers

how to make an enemy into a second player 0 Answers

Advance AI ( League of Legends ) 0 Answers

How do I make an enemy go through walls, etc and follow then kill the player? 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