Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Firen_SVK · Jul 19, 2015 at 07:00 PM · playerattackzombiewhy

Why Zombie clones dont take Player's HP?

Hi. I make Zombie.prefab with this code:

 using UnityEngine;
 using System.Collections;
 
 public class FollowBotAI : MonoBehaviour {
 
     Transform Leader;
     float AISpeed = 1;
     float MaxDistance = 10;
     float MinDistance = 1.5f;
     public bool attack = false;
     public bool dead = false;
 
     public int MaxHP = 5;
     public int CurHP;
 
     private Animator anim;
 
     void Start () {
         Leader = GameObject.FindGameObjectWithTag ("Player").transform;
         anim = gameObject.GetComponent<Animator> ();
 
         CurHP = MaxHP;
     }
     
     void Update () 
     {
         anim.SetFloat ("speed", AISpeed);
         anim.SetBool ("attack", attack);
         anim.SetBool ("dead", dead);
 
         transform.LookAt (Leader);
         AI ();
 
         if (CurHP == 0) 
         {
             dead = true;
         }
     }
 
     void AI()
     {
         if (Vector3.Distance (transform.position, Leader.position) >= MinDistance) {
             transform.position += transform.forward * AISpeed * Time.deltaTime;
             attack = false;
             
         } else 
         {
             attack = true;
         }
     }
 
     void AIDie()
     {
         Destroy (gameObject);
     }
 }
 

Main priority is true or false "attack". I have Player with this HP behavior code:

 using UnityEngine;
 using System.Collections;
 
 public class HPbehavior : MonoBehaviour {
 
     public GameObject zombie;
 
     public int maxHP = 100;
     public int curHP;
 
     private FollowBotAI botAI;
 
     void Start()
     {
         curHP = maxHP;
         botAI = zombie.GetComponent<FollowBotAI> ();
     }
 
     void Update()
     {
         if (botAI.attack == true) 
         {
             curHP = curHP - 1;
         }
 
         if (curHP <= 0) 
         {
             Destroy(this.gameObject);
         }
     }
 
     void OnGUI()
     {
         string textHP = "Health: " + (curHP);
         GUI.Box (new Rect (Screen.width - 150, 20, 130, 20), textHP);
     }
 
 }
 

Well...if attack is true, HP is losing. I put my Zombi.prefab in to HPbehavior: alt text

In my Zombi.prefab is Code FollowBotAI: alt text

I dont know why Zombi(clones) dont take Player's HP. What is wrong with my Codes? I check if attack is real true, when zombie attacking Player. Yes, it is. But it ignore my condition in HPbehavior code. PLease help me...

untitled2.jpg (290.9 kB)
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Zombie Alien Mellee Attack 1 Answer

Ai Zombie Melee Attack script. 5 Answers

Zombie attack script help 1 Answer

How do I make it so that I can attack more than 1 enemy? 1 Answer

Follow Player Via Waypoints 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