Search Unity

Need Help With Zombies

Discussion in 'Scripting' started by Willy_2202, Apr 29, 2015.

  1. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok so I need some help with my code. I want an animation to happen after I kill all the zombies (100) I know basic javascript. Here is my code:

    Code (JavaScript):
    1.  #pragma script
    2.    
    3.      var Zombie2 = 100;
    4.    
    5.      if (Zombie2 < 0) { GetComponent.().Play("Elevator"); }
    Thanks :)
     
  2. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Alright, well, you're using GetComponent with an empty argument... I presume that you're trying to gain access to an attached Animator component? Try this instead and let me know if it helps any (untested, top of my head)...

    Code (JavaScript):
    1.      #pragma script
    2.      
    3.          var Zombie2 = 100;
    4.      
    5.          if (Zombie2 < 0) { GetComponent.(Animator).Play("Elevator"); }
    6.  
     
  3. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    I have the following errors:

    (5,21) Unexpected Token: ..
    (5,22) Insert semicolon at the end
     
  4. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    GetComponent(Animator) not GetComponent.(Animator)
     
  5. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok so there are no errors, the animation is working, but the animation plays right away and is ignoring the if statement.
    I want the animation to play after i kill 100 zombies (i changed it to 1 for testing purposes) Is it the script or do I have to change something in the Cube (animator property)?
     
  6. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    All you've shown is a variable called Zombie2, and a condition that if that variable is BELOW zero, then an animation gets played.

    What decrements this variable? Do you have something somewhere that says "when a zombie is killed, Zombie2 = Zombie2 - 1"?

    Additionally, I'd expect this comparison to be inside an Update() loop.
     
  7. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    My apologies, I've gotten used to C# and so Javascript now seems almost prehistoric. I love how unforgiving C# is because it forces you to declare your intentions properly, whereas JS is exceedingly forgiving & will allow you to declare variables without setting their type, etc. All that aside, as BenZed (love the avatar btw) said, where exactly are you decrementing the amount of zombies? Also, will there ever be less then 0 zombie2 at any point? Even when you have none, that's 0... so how are you supposed to reach less than that?
     
  8. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Well I tried to put "Zombie2 = 0" but got an error...
    I dont know a whole lot of coding all I've programmed before was programming buttons (start game, exit game, ect...)

    Is it okay if you go more in depth im 12 and im trying to make a really cool game for everyone because im not very cool and I want to be a video game designer when I grow up so I want to start early...
     
    Last edited: May 1, 2015
  9. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    First, don't say you're not cool. Confidence plays a huge role in how successful you will be in your life; practice being confident. It doesn't matter what a few people might say about you. Some people are going to think you are pretty cool.

    Second, it's great that you are starting young while your brain still has the plasticity to develop a capacity for writing code and developing software. The older you are the harder it becomes to learn this stuff.

    Third, learn C# if you want to be a game developer. Do not use Javascript just because it seems a little easier. C++/C# are pretty much an industry standard for object oriented programming and both of those languages are more applicable than Javascript in the game development field.

    Lastly, your code snippet does not give enough information to solve your problem. As others before me have stated, we don't know how the Zombie2 variable is decremented. What you need to do is write a script that subtracts 1 from the Zombie2 variable every time you eliminate a zombie. Then once Zombie2 reaches 0 your if statement should play the animation. That animation would be handled a little differently in C#

    Code (CSharp):
    1. int Zombie2 = 100;
    2. if(Zombie2 =< 0){
    3.     gameObject.GetComponent<Animator>().Play("Elevator");
    4. }
    I advise you to go through these tutorials before you try to tackle a project of your own: https://unity3d.com/learn/tutorials/modules

    Pace yourself; you are only 12 and you have lots of time to learn all of this stuff.

    Good Luck!
     
    krougeau, JoeStrout and BenZed like this.
  10. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    I agree with everything @Hamsterbyte.LLC just said. I've been teaching programming to middle schoolers all semester, and I will say that you're way ahead of the curve; your only misstep was in choosing JS over C#, but that's easily fixed (do it now!).

    I would add that "Need Help With Zombies" is the coolest thread title I've seen all day. It conjures up images of you barricaded behind an overturned table, desperately posting for help to the Unity forums while the zombies try to break down your door. Not a very informative subject, perhaps, but very evocative — it certainly caused me to click on it!

    Cheers,
    - Joe
     
  11. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,694
    ^ Me too. :)
     
    krougeau likes this.
  12. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    You must be cool, kiddo! You're already working on something that very few people have the willingness to learn :) I'm almost 40 and am just getting into this stuff myself, so I can only imagine how awesome your games will be by the time you're my age haha! Keep at it, and hit us up for help any ol' time.
     
  13. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    As Hamsterbyte,LLC asked, do you have anything in your code that subtracts from your Zombie2 count when a zombie is killed? If not, then the total will always be 100. When a zombie is destroyed, something should tell this script that Zombie2--;
    or
    Zombie2 = Zombie2 - 1;
    so that your total goes down. Once you've got something like that in place, and you've adjusted your if statement as Hamsterbyte.LLC instructed, things _should_ (hopefully) work out fine. If not, we're here :)
     
  14. Stef_Morojna

    Stef_Morojna

    Joined:
    Apr 15, 2015
    Posts:
    289
    I was 11 when I started making games.
     
    krougeau likes this.
  15. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Thanks man, you made my day :)
     
    krougeau likes this.
  16. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok question, to put the "Zombie2 - 1" would it be in the same, or different script.
    Second can you maybe do a little example of what I should put for this^
    All I know is " If zombie2(Clone) is destoryed (Zombie2 - 1), how would I put this into script "Form"...
     
  17. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    I'm quite happy to work up a quick example for you, but you'll have to give me a couple of hours. I'm in the middle of watching TV with my better half, and that's quality time haha :) Back soon!
     
  18. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Alright, I'm back. Now then, assuming that the code you've shown us so far is attached to your elevator, let's make a couple of minor adjustments:

    Code (CSharp):
    1. public int Zombie2 = 100; // amount of zombies to start with
    2. public int ticks = 0; //a simple counter
    3.  
    4. void Update() // called once per frame
    5. {
    6.     if(Zombie2 =< 0 && ticks == 0) // if there are 0 or less zombies and our ticks counter is still at 0
    7.     {
    8.         ticks++; // add 1 to our ticks counter (this makes sure this will only happen once and not over and over every frame)
    9.         gameObject.GetComponent<Animator>().Play("Elevator"); // get access to the Animator component of this object & play the "Elevator" animation
    10.         Debug.Log(gameObject.name + " says there are no zombies left! Playing the Elevator animation now!"); // write a message to the console so we can see when it happens
    11.     }
    12. } // end of Update() function
    13.  
    14. public void ZombieDied() // we'll be calling this from whatever script is attached to the Zombies
    15. {
    16.    Zombie2--; // subtract 1 from whatever number Zombie2 is currently
    17.    Debug.Log(gameObject.name + "  reports that the number of zombies is now " + Zombie2); // write a message to the console so that we know how many zombies there are
    18. } // end of ZombieDied() function
    Now that we have the elevator code in place, let's make the zombies tell the elevator when they die... Something like this next piece of code should be placed on your zombies, in whatever function you're using to Destroy them. Just as an example:

    Code (CSharp):
    1. public int health = 100; // whatever health the zombie has
    2. public GameObject elevator; // the Elevator gameobject in your scene (drag and drop in the Inspector)
    3.  
    4. void Update()
    5. {
    6.    if(health <= 0) // when the zombie's health is 0 or less,
    7.    {
    8.         elevator.BroadcastMessage("ZombieDied"); // tell the elevator script to subtract 1 zombie
    9.         Debug.Log(gameObject.name + " is dead. Subtracting one from Elevator's Zombie2 counter."); // write a line to the console so that we know when this is happening
    10.         Destroy(gameObject); // and destroy the zombie
    11.    }
    12. } // end Update() function
    13.  
    Again, this is just a rough example of what you might do. There are a lot of ways to approach this, and several ways of making scripts talk to each other. I'm using this method because I'm showing you C# and you're already using JavaScript. The two don't always get along together, but the BroadcastMessage call should be able to bridge the gap between them just fine. I've added Debug lines so that you can tell when things are happening by watching your Console as well. They're not necessary, but may help :) Let me know how it goes!
     
    Last edited: May 2, 2015
    hamsterbytedev likes this.
  19. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Okay I can't try it right away, but I will make script files for these, but I will have to do it later today (grandmaws lol)
     
    krougeau likes this.
  20. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    No worries, just let me know how it works out when you get a chance to test it and we'll take it from there. Have fun!
     
  21. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    I just got tons of errors about name spaces and stuff lol
     
  22. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    When you get an error, copy the actual error right out of the Console, and paste it into your forum post. It helps to paste the whole script code too, as long as it's no more than a page or two of code -- just be sure to use the Code tags so it's formatted nicely.

    With the code and error message in hand, you're sure to get the help you need!
     
  23. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    As Joe Strout stated, we'll be better able to assist you if we know what errors you're receiving. I'd also like to know how you used the examples provided. Did you alter your own code to do the kinds of things I was attempting to show you, or did you just drop my code in there and cross your fingers? The latter may well give you errors. It was, after all, just an example of what you _could_ do with your own code. Come to think of it, they're not even full C# scripts as I haven't named classes or included dependencies. Which brings me to the last question. The above code was in C# and not Javascript, so if you tried putting these lines inta a JS file, you'd certainly receive errors as well. That said, here is a "full" example of what the proper C# scripts would look like. Again, they're just examples and may not work specifically for your needs, but they should illustrate one possibility and will hopefully help illuminate the road ahead for you... Let's see...

    This code would need to be in a C# file called ElevatorScript.cs:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ElevatorScript : MonoBehaviour {
    5.  
    6.     public int Zombie2 = 100; // amount of zombies to start with
    7.     public int ticks = 0; //a simple counter
    8.    
    9.     void Update() // called once per frame
    10.     {
    11.         if(Zombie2 =< 0 && ticks == 0) // if there are 0 or less zombies and our ticks counter is still at 0
    12.         {
    13.             ticks++; // add 1 to our ticks counter (this makes sure this will only happen once and not over and over every frame)
    14.             gameObject.GetComponent<Animator>().Play("Elevator"); // get access to the Animator component of this object & play the "Elevator" animation
    15.             Debug.Log(gameObject.name + " says there are no zombies left! Playing the Elevator animation now!"); // write a message to the console so we can see when it happens
    16.         }
    17.     } // end of Update() function
    18.    
    19.     public void ZombieDied() // we'll be calling this from whatever script is attached to the Zombies
    20.     {
    21.         Zombie2--; // subtract 1 from whatever number Zombie2 is currently
    22.         Debug.Log(gameObject.name + "  reports that the number of zombies is now " + Zombie2); // write a message to the console so that we know how many zombies there are
    23.     } // end of ZombieDied() function
    24.  
    25. } // end of ElevatorScript class
    And this code would need to be in a C# file called ZombieMaster.cs:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ZombieMaster : MonoBehaviour {
    5.  
    6.     public int health = 100; // whatever health the zombie has
    7.     public GameObject elevator; // the Elevator gameobject in your scene (drag and drop in the Inspector)
    8.    
    9.     void Update()
    10.     {
    11.         if(health <= 0) // when the zombie's health is 0 or less,
    12.         {
    13.             elevator.BroadcastMessage("ZombieDied"); // tell the elevator script to subtract 1 zombie
    14.             Debug.Log(gameObject.name + " is dead. Subtracting one from Elevator's Zombie2 counter."); // write a line to the console so that we know when this is happening
    15.             Destroy(gameObject); // and destroy the zombie
    16.         }
    17.     } // end Update() function
    18.  
    19. } // end of ZombieMaster script class
    You can actually call the files and the classes whatever you'd like, so long as the Filename and Class Name match. Let me know if these additional bits and bobs help any.
     
  24. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Okay, yes they were in c# and I have tried these new ones you sent me, before I put them on any object (Elevator, Zombie, ect) I have gotten the following errors for the "ElevatorScript.cs Only" :

    (11,21) Unexpected Symbol '<'
    (19,17) A namespace can only contain types and namespace declarations
    (25,1)Parsing Error

    ElevatorScript.cs:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class ElevatorScript : MonoBehaviour {
    4.     public int Zombie2 = 100; // amount of zombies to start with
    5.     public int ticks = 0; //a simple counter
    6.  
    7.     void Update() // called once per frame
    8.     {
    9.         if(Zombie2 =< 0 && ticks == 0) // if there are 0 or less zombies and our ticks counter is still at 0
    10.         {
    11.             ticks++; // add 1 to our ticks counter (this makes sure this will only happen once and not over and over every frame)
    12.             gameObject.GetComponent<Animator>().Play("Elevator"); // get access to the Animator component of this object & play the "Elevator" animation
    13.             Debug.Log(gameObject.name + " says there are no zombies left! Playing the Elevator animation now!"); // write a message to the console so we can see when it happens
    14.         }
    15.     } // end of Update() function
    16.  
    17.     public void ZombieDied() // we'll be calling this from whatever script is attached to the Zombies
    18.     {
    19.         Zombie2--; // subtract 1 from whatever number Zombie2 is currently
    20.         Debug.Log(gameObject.name + "  reports that the number of zombies is now " + Zombie2); // write a message to the console so that we know how many zombies there are
    21.     } // end of ZombieDied() function
    22. } // end of ElevatorScript class

    Again the ZombieMaster.cs script you have sent me hass no errors at all.
     
  25. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    OK, well I see a couple of things we can do here. First, I think I made a mistake and had =< instead of <= on one line, and that may be responsible for the other errors. If not, the other place "<" might be causing problems is in the line where the Animator is accessed and the animation is played, so let's change our approach there, too, and get access to the Animator from Start.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ElevatorScript : MonoBehaviour
    5. {
    6.     public int Zombie2 = 100; // amount of zombies to start with
    7.     public int ticks = 0; //a simple counter
    8.     private Animator anim; // the Animator component attached to this object
    9.  
    10.     void Start()
    11.     {
    12.         anim = GetComponent<Animator>(); // get access to the Animator attached to this object
    13.     }
    14.  
    15.     void Update() // called once per frame
    16.     {
    17.         if(Zombie2 <= 0 && ticks == 0) // if there are 0 or less zombies and our ticks counter is still at 0
    18.         {
    19.             ticks++; // add 1 to our ticks counter (this makes sure this will only happen once and not over and over every frame)
    20.             anim.Play("Elevator"); // get access to the Animator component of this object & play the "Elevator" animation
    21.             Debug.Log(gameObject.name + " says there are no zombies left! Playing the Elevator animation now!"); // write a message to the console so we can see when it happens
    22.         }
    23.     } // end of Update() function
    24.  
    25.     public void ZombieDied() // we'll be calling this from whatever script is attached to the Zombies
    26.     {
    27.         Zombie2--; // subtract 1 from whatever number Zombie2 is currently
    28.         Debug.Log(gameObject.name + "  reports that the number of zombies is now " + Zombie2); // write a message to the console so that we know how many zombies there are
    29.     } // end of ZombieDied() function
    30.  
    31. } // end of ElevatorScript class
     
  26. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Let me try it and I will tell you...
     
    krougeau likes this.
  27. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok so no errors, I have put all scripts on all objects, but the cube (elevator) plays its animation before I even kill 1 zombie... Do I have to change something in the animation properties for the Cube (Elevator)?
     
  28. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Perhaps. Have a look at the Animation and make sure it's not set to Play On Awake. Other than that, I can't be sure offhand, but I'll be happy to help further if you need & when I can :)
     
  29. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    There is no Play On Awake but there is a "Always Animate", "Cull Completely", and "Cull Update Transforms"
     
  30. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Ah! In that case, my guess is that the "Elevator" animation is the Animator's default state, so it's played automatically. Again, this is just a guess, but open the Animator window and see (the Default animation is typically colored orange). If this is in fact the case, the simplest thing to do would be to create a new state in the Animator and set it to be the default. To do this, open the Animator window, right-click on an empty area and select Create State -> Empty (name it anything you want, or just leave it as New State), then right-click the new state and choose Set As Layer Default State. Hopefully that will do the trick :)

    Alternately, you could put anim.StopPlayback(); in the elevator's Start or Awake functions, but that's inelegant at best and may still give you undesired results. Best to try the above method & see if that works for you.

    My apologies for keeping you waiting; it's been a long day and I'm going to get some much needed rest. If you need further assistance, however, I will be checking back in on your progress in the morning. Best of luck & have fun!!
     
  31. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Im at my grandmaws but I sure will try that when I get home tonight....
    Thanks
     
    krougeau likes this.
  32. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    We'll be here :)
     
  33. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok so I did what you said the animation is playing, but no matter how many zombies I kill it wont play the animation.
     
  34. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    I'm confused. You've said the animation is playing and the animation isn't playing... Honestly, without seeing the project & how you're setting things up, I'm left to guess, and that guesswork doesn't seem to be doing you much good.

    When you kill the first zombie, do you get a message on the console that says something like "Elevator reports that the number of zombies is now 99"? I had you put the various Debug lines in so that you can tell if and when things are being executed.

    Are you receiving any errors? Are you seeing any of the debug lines?
     
  35. Stef_Morojna

    Stef_Morojna

    Joined:
    Apr 15, 2015
    Posts:
    289
    It would be practical if when a zombie is spawned it adds +1 to the total zombies in the scene
    Each time a zombie dies the total zombies go down by 1
     
  36. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456

    Very good point. I hadn't considered that the OP might be spawning the zombies, and had just assumed they had a scene filled with 100 of them. This very well may be the heart of the issue :) As I'd said above, this has all been guesswork so far since we really don't have the details on just how the OP has their scene set up.
     
  37. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Here are some script alterations to try, based on the assumption that the zombies are being spawned...

    ZombieMaster.cs:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ZombieMaster : MonoBehaviour {
    5.  
    6.     public int health = 100; // whatever health the zombie has
    7.     public GameObject elevator; // the Elevator gameobject in your scene (drag and drop in the Inspector)
    8.     private int ticks = 0; // a simple counter
    9.  
    10.     void Update()
    11.     {
    12.         if(health <= 0 && ticks == 0) // when the zombie's health is 0 or less & our ticks counter is 0
    13.         {
    14.             ticks++;  // add 1 to our ticks counter so this code is only processed once
    15.             elevator.BroadcastMessage("ZombieDied"); // tell the elevator script to add 1 to the number of zombies killed
    16.             Debug.Log(gameObject.name + " is dead. Adding one to the Elevator's zombiesKilled counter."); // write a line to the console so that we know when this is happening
    17.             Destroy(gameObject); // and destroy the zombie
    18.         }
    19.     } // end Update() function
    20.  
    21. } // end of ZombieMaster script class
    ElevatorScript.cs:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ElevatorScript : MonoBehaviour
    5. {
    6.     private int zombiesKilled = 0; // count of how many zombies have been killed by the player
    7.     private int ticks = 0; // a simple counter
    8.     private Animator anim; // the Animator component attached to this object
    9.  
    10.     void Start()
    11.     {
    12.         anim = GetComponent<Animator>(); // get access to the Animator attached to this object
    13.     }
    14.  
    15.     void Update() // called once per frame
    16.     {
    17.         if(zombiesKilled == 100 && ticks == 0) // if 100 zombies have been killed and our ticks counter is at 0
    18.         {
    19.             ticks++; // add one to our ticks counter so that this code is only processed once
    20.             anim.Play("Elevator"); // get access to the Animator component of this object & play the "Elevator" animation
    21.             Debug.Log(gameObject.name + " says 100 zombies have been killed! Playing the Elevator animation now!"); // write a message to the console so we can see when it happens
    22.         }
    23.     } // end of Update() function
    24.  
    25.     public void ZombieDied() // we'll be calling this from whatever script is attached to the Zombies
    26.     {
    27.         zombiesKilled++; // add 1 to zombiesKilled
    28.         Debug.Log(gameObject.name + "  reports that the player has killed " + zombiesKilled + " zombies!"); // write a message to the console so that we know how many zombies there are
    29.     } // end of ZombieDied() function
    Hopefully that'll work better for ya! :)
     
    Last edited: May 4, 2015
  38. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Im sorry I didnt even get that lol ignore that ok so what happened is no matter how many zombies I kill the animation WONT play lol sorry
     
  39. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Give the above changes a try and see if you have any better luck... I am wondering though, how it is you're killing the zombies at all since we haven't put in anything to take away their health... Again, a problem with not knowing just how you have things set up.
     
  40. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok so I tried your new script, no errors, everything is fine, but the animation wont play, if you send me another script send two copys one for testing (change 100 to 1) the other leave at 100.
     
  41. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Oh I already had all that set up maybe this will help, I downloaded a kit from a website, I wanted to add this, the killing and all that was already in the kit.

    Link to kit: http://armedunity.com/files/file/13-fps-kit-2/

    Here use this kit and try and get my problem to work see if you can do anything.
     
  42. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    It's gonna be a bit before I have time to help you quite that extensively. I'm in the middle of several projects myself, not to mention trying to fix a few issues of my own, plus life's other general complications, haha. You, however, can easily change 100 to 1 and see what happens after killing 1 zombie, so I'm not sure why you'd need me to test that...

    As for the animation not playing, it's one more thing that you're in a better spot to troubleshoot than I am; I don't have your elevator, so I can't see how it's set up or test it. I have a feeling we're just missing something simple in the mix...

    What you could do is select your Elevator object in the Hierarchy and show us all a screenshot of how you have it setup in your Inspector. I'd also like to see a shot of one of your zombie's Inspector settings, just so I can gauge any other issues that I may be missing there. If you need helping with taking or posting screenshots, let me know.
     
  43. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok right now the elevator is just a cube for testing, but I cant post the pictures they have an error:

    The uploaded file is too large for the server to process.
     
  44. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Ooookay... I'm not sure how swapping the elevator for a cube is going to help anything, but if you're doing it that way, (1) does the cube have an Animator component, and (2) does it have an animation called Elevator? As for the large images, how are you taking your screenshots? You should be able to scale down the size or quality so that they're not so big, but I suppose that depends on what image software you're using to do it.
     
  45. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Cube has all of those things yes...
    I will try scaling down the pics, I was using paint lol
     
  46. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Pictures Below:

    Cube(elevator):
    Elevator.png

    Zombie Pic 1:

    Zombie1.png

    Zombie Pic 2:

    Zombie2.png

    Sorry for such large pics...
     
  47. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    Aha! Looks like the problem is actually with the zombie setup... You've got hit points defined in two places, as different things I might add, and health in yet a third place. Odds are, none of these scripts are talking to each other, so you'll need to narrow it down to just one place. Happy to help further shortly, but I'm caught up in something else at the moment & won't be free for a couple of hours.
     
  48. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    OK, first you can delete the ZombieMaster script from your zombies. It's pointless. Then, I need you to figure out which one of your scripts is really controlling your zombie's hit points... You can shoot one and then look at it in the Inspector to see which script's Hit Points value is going down, AI or ZombieDamage. It might even be both... Once we know which script is actually running the show, we can add some code to it so that it tells the ElevatorScript when a zombie dies. If you figure out which script it is, please post that script here so I can have a look and help you properly fix it.
     
  49. Willy_2202

    Willy_2202

    Joined:
    Feb 19, 2015
    Posts:
    50
    Ok its the Zombie Damage Script, the "Hit Points" go down when I shoot one, and when "Hit Points = 0" the zombie dies...

    ZombieDamage:

    Code (JavaScript):
    1.  
    2. var maximumHitPoints = 100.0;
    3. var hitPoints = 100.0;
    4. var deadReplacement : Rigidbody;
    5. var GOPos : GameObject;
    6. var scoreManager : ScoreManager;
    7.  
    8. function Start(){  
    9.     scoreManager = gameObject.Find("ScoreManager").GetComponent("ScoreManager");
    10. }
    11.  
    12. function ApplyDamage (damage : float) {
    13.     if (hitPoints <= 0.0)
    14.         return;
    15.  
    16.     // Apply damage
    17.     hitPoints -= damage;
    18.     scoreManager.DrawCrosshair();
    19.     // Are we dead?
    20.     if (hitPoints <= 0.0)
    21.         Replace();
    22. }
    23.  
    24. function Replace() {
    25.  
    26.     // If we have a dead barrel then replace ourselves with it!
    27.     if (deadReplacement) {
    28.         var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
    29.         scoreManager.addScore(20);
    30.         // For better effect we assign the same velocity to the exploded barrel
    31.         dead.GetComponent.<Rigidbody>().velocity = GetComponent.<Rigidbody>().velocity;
    32.         dead.angularVelocity = GetComponent.<Rigidbody>().angularVelocity;
    33.     }
    34.     // Destroy ourselves
    35.     Destroy(gameObject);
    36. }
    37.  
    38.  
    39.  
    Its in javascript, but I didnt make it....
    Here you go :)
     
  50. krougeau

    krougeau

    Joined:
    Jul 1, 2012
    Posts:
    456
    No worries :) The little bit that I'm going to add won't have me scratching my head much over syntax, haha, so JS is fine. Let's see...
    Code (JavaScript):
    1. var maximumHitPoints = 100.0;
    2. var hitPoints = 100.0;
    3. var deadReplacement : Rigidbody;
    4. var GOPos : GameObject;
    5. var scoreManager : ScoreManager;
    6. var elevator : GameObject; // assign this in the Inspector
    7.  
    8. function Start(){
    9.     scoreManager = gameObject.Find("ScoreManager").GetComponent("ScoreManager");
    10. }
    11.  
    12. function ApplyDamage (damage : float) {
    13.     if (hitPoints <= 0.0)
    14.         return;
    15.     // Apply damage
    16.     hitPoints -= damage;
    17.     scoreManager.DrawCrosshair();
    18.     // Are we dead?
    19.     if (hitPoints <= 0.0)
    20.         Replace();
    21. }
    22.  
    23. function Replace() {
    24.     // If we have a dead barrel then replace ourselves with it!
    25.     if (deadReplacement) {
    26.         var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
    27.         scoreManager.addScore(20);
    28.         // For better effect we assign the same velocity to the exploded barrel
    29.         dead.GetComponent.<Rigidbody>().velocity = GetComponent.<Rigidbody>().velocity;
    30.         dead.angularVelocity = GetComponent.<Rigidbody>().angularVelocity;
    31.     }
    32.     elevator.BroadcastMessage("ZombieDied"); // tell the elevator script to add 1 to the number of zombies killed
    33.     Debug.Log(gameObject.name + " is dead. Adding one to the Elevator's zombiesKilled counter."); // write a line to the console so that we know when this is happening
    34.     // Destroy ourselves
    35.     Destroy(gameObject);
    36. }
    That should do it... Then again, you've fooled me before, hahaha. As you can see by comparing the two, I've only added three lines of code. The first is the "elevator" GameObject variable, then the BroadcastMessage shout out to the elevator, and finally a debug line so that you'll see in the console when this is happening. Let me know how it goes! :)
     
    JoeStrout likes this.