Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Survival Shooter Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 26, 2015.

Thread Status:
Not open for further replies.
  1. LtCodename

    LtCodename

    Joined:
    Jun 12, 2013
    Posts:
    7
    After I'm killing Zombunny the death animation doesn't play and the bunny just freezes on the scene. Also I see a following mistake in the console:

    Anyone knows how to deal with this?
     
  2. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    I think you didn't create a Dead parameter in the Zombunny animator. That 's why when you kill one (and the script try to change the animator string to Dead) it doesn't works. That or you spelt it wrong.
     
  3. LtCodename

    LtCodename

    Joined:
    Jun 12, 2013
    Posts:
    7
    Yeah, eventually I found a problem in the animator, thanks.

    But I have another issue. I just can't get rid of this error:

    In the part 7 of the tutorial guys are telling to uncomment some stuff in EnemyMovement script. I did so! But the game is still shutting down after 2-3 seconds with this error. What am I missing here?
     
  4. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Well the message is clear. You're trying to modify a navmesh on an object that does not have one. Did you bake the navmesh ? Did you had the navmesh Agent component on the object to which the script is attached ?

    Edit : Alright. I had the same error too at the end of phase 7. But I found where it's comming from.

    First let me guess. The error doesn't appear until you've killed the Zombunny right ? The explanation is realy simple. In our enemyMovement script in our update function we update the navmeshagent Destination to the player current position. Every single frame. So that our Zombunny adapt is path. But here is the catch? Once he is dead, well no more Bunny, no more NavMeshAgent. So nothing to update. And so unity tell us there is no more active agent on the navmesh, and nothing to update anymore.

    But I don't understand why the script don't stop since the Zombunny is deleted from the scene.

    Edit 2 : Just like I thought this issue is not an issues as we change the script later and there is no more error. For that, you just need to uncomment all the lines in the script. There is a If condition, and the death of the Zombunny dsable the Navmesh component.
     
    Last edited: Apr 26, 2015
  5. LtCodename

    LtCodename

    Joined:
    Jun 12, 2013
    Posts:
    7
    The navmesh is definitely baked, and the navmesh agent is attached to every spawning enemy prefeb (there are three types of them).

    And the error appears despite killing the Zombunny. I may not do anything after launching the game and error is still there.
     
  6. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Isn't it like in my edited message ?
     
  7. LtCodename

    LtCodename

    Joined:
    Jun 12, 2013
    Posts:
    7
    As I've said before, I've uncommented all lines in the script...
     
  8. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Is there nothing else ? Because in my case there was the error line. Can you post your script ?
     
  9. LtCodename

    LtCodename

    Joined:
    Jun 12, 2013
    Posts:
    7
    Here is my EnemyMovement script

    I can upload whole project to show you.
     
    Last edited: Apr 26, 2015
  10. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Do you have the full error message too ?
     
  11. Jesuo

    Jesuo

    Joined:
    Apr 19, 2015
    Posts:
    2


    Well, at the momment i can say it is a problem with baking.
    Into Lightning window and a light selected (in this case Moonlight)..... continuos baking option....seems not working correctly, if you clear baked data seems to fix the problem but you must build it, so i think it is related to navmesh, lights and corrupt baked data.
     
  12. MikexUr

    MikexUr

    Joined:
    Mar 5, 2015
    Posts:
    1
    Hi, I finish thew phase 2, but i'm creating my own environment and player, wen i finish coding the player movement script i found that my player doesn't move at all. my script looks ok because a don;t have any errors. As you see in the code, i have commented any line related to animation because i don't want to used at this moment. i'm using a cylinder like temporally player... do i have a problem related to the version of unity o is because i have something wrong. i'm using Untiy 5.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerMovement : MonoBehaviour {
    5.  
    6.     // Variables
    7.     public float speed = 6f;
    8.     Vector3 movement;
    9.     //Animator anim;
    10.     Rigidbody playerRigidbody;
    11.     int floorMask;
    12.     float camRayLength = 100f;
    13.  
    14.     //Awake
    15.     void  Awake()
    16.     {
    17.         floorMask = LayerMask.GetMask("Floor");
    18.         //anim = GetComponent<Animator>();
    19.         playerRigidbody = GetComponent<Rigidbody>();
    20.     }//end Awake
    21.  
    22.     // Update is called once per frame
    23.     void FixUpdate ()
    24.     {
    25.         //Horizontal input
    26.         float h = Input.GetAxisRaw("Horizontal");
    27.         //Vertical input
    28.         float v = Input.GetAxisRaw("Vertical");
    29.  
    30.         Move (h, v);
    31.         Turning();
    32.         //Animating(h, v);
    33.     }//end FixUpdate
    34.  
    35.     //Move Function
    36.     void Move(float h, float v)
    37.     {
    38.         movement.Set(h, 0f, v);
    39.         movement = movement.normalized * speed * Time.deltaTime; //normalized the movement
    40.         playerRigidbody.MovePosition (transform.position + movement);
    41.     }//end Move
    42.  
    43.     //Turning function
    44.     void Turning()
    45.     {
    46.         Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
    47.         RaycastHit floorHit;
    48.  
    49.         if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
    50.         {
    51.             Vector3 playerToMouse = floorHit.point - transform.position;
    52.             playerToMouse.y = 0f;
    53.  
    54.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    55.             playerRigidbody.MoveRotation(newRotation);
    56.         }
    57.     }//end turning
    58.  
    59.     /*void Animating(float h, float v)
    60.     {
    61.         bool walking = h != 0f || v != 0f;
    62.         anim.SetBool("IsWalking", walking);
    63.     }//end Animating*/
    64. }
    65.  
     
  13. bongpaddle

    bongpaddle

    Joined:
    Apr 30, 2015
    Posts:
    1
    Hi. So I'm on lesson 4, where you're supposed to create the enemies and have them follow you. I got to the end of the lesson and am having a problem with the enemy. He'll move and walk towards my character, but only goes to where the player spawned. Once he reaches that point, he just keeps walking in place.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnemyMovement : MonoBehaviour
    5. {
    6.     Transform player;
    7.     //PlayerHealth playerHealth;
    8.     //EnemyHealth enemyHealth;
    9.     NavMeshAgent nav;
    10.  
    11.  
    12.     void Awake ()
    13.     {
    14.         player = GameObject.FindGameObjectWithTag ("Player").transform;
    15.         //playerHealth = player.GetComponent <PlayerHealth> ();
    16.         //enemyHealth = GetComponent <EnemyHealth> ();
    17.         nav = GetComponent <NavMeshAgent> ();
    18.     }
    19.  
    20.  
    21.     void Update ()
    22.     {
    23.         //if(enemyHealth.currentHealth > 0 && playerHealth.currentHealth > 0)
    24.         //{
    25.         nav.SetDestination (player.position);
    26.         //}
    27.         //else
    28.         //{
    29.         //    nav.enabled = false;
    30.         //}
    31.     }
    32. }
     
  14. Camike

    Camike

    Joined:
    Mar 26, 2015
    Posts:
    5
    How do I post a new thread here (Survival Shooter Q&A)? I only have that option 1 level up... otherwise I am replying to something else...
     
    Last edited: May 1, 2015
  15. Xesko

    Xesko

    Joined:
    Apr 15, 2015
    Posts:
    1
    Hi all. I've been following cool tutorial. Got to end and everything worked well. However, my problem comes when I try to set a longer time for the Game Over screen (Restart Delay), so it takes longer for the game to restart. I've changed the amount of seconds to 20, but the game always restarts itself after two or three, no matter what value I put there. Any ideas? I'm pretty sure the code GameOverManager class is fine, but I saw that in my version of the script as I downloaded it some lines were missing according to what they say in the video, so I put them in (all the code related to Application.LoadLevel and what was needed for it to work). I added the code, but the restart delay doesn't seem to be working. I wonder if it's something 5.0.1 related. Any ideas?

    Many thanks in advance!
     
  16. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Can you upload your code ?
     
  17. DSmith15

    DSmith15

    Joined:
    Apr 9, 2015
    Posts:
    4
    Hello,
    I am on the last few minutes of the second tutorial and I have looked over the code a million times but it says my "!" is unexpected when I place it after the h and v of the animating function and I have no idea why. It says its a Parser error and its error CS1525. Could you please tell me why this might be happening.

    void Animating (float h, float v)
    {
    bool walking = h ! = 0f || v ! = 0f;
    anim.SetBool ("IsWalking", walking);
    }

    Everything else seems to be working fine.
     
  18. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    No space between you ! and your =.
     
  19. DSmith15

    DSmith15

    Joined:
    Apr 9, 2015
    Posts:
    4
    I tried it both with a space and without a space and neither seems to work
     
  20. 8beat

    8beat

    Joined:
    May 6, 2015
    Posts:
    4
    I have the same error in Unity5.
    Anyone has any solution plz???
    Debug log shows the player position isn't updated every frame.
    I put player = GameObject.FindGameObjectWithTag ("Player").transform; this code in the Update in EnemyMovement, but still not working...

    I got it working!
    Replace
    player = GameObject.FindGameObjectWithTag ("Player").transform;
    to
    player = GameObject.Find ("Player").transform;

    Happy coding!
     
    Last edited: May 6, 2015
    Xpak likes this.
  21. Mr B

    Mr B

    Joined:
    May 5, 2015
    Posts:
    3
    doubleScoreManager.PNG

    Hi, I just want to put this out of the way. Since it can happen to anyone, including me... In the excellent Survival Shooter tutorial, there are two Score Manager scripts. The one you need is the one on the top. If you select the one on the bottom, the score will not add up for some reason. The one on the bottom is the one in the _Completed Assets folder. As soon as I changed to the top one, the score was adding up just fine. And well of course you bet I do not know the reason!... But I am 100% sure another guy can figure it out. I did not find this on the forums, so, here it is.
     

    Attached Files:

    Last edited: May 7, 2015
  22. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    606
    I imported the complete project in unity 5, let it update the api and this is what happens even though I rebaked the nav mesh. This is using the completed scene.

     
  23. Scalding

    Scalding

    Joined:
    May 7, 2015
    Posts:
    1
    I've just "finished" session 3, so the camera is set up and I can move the character around the game world. When I do, I get this error:

    NullReferenceException: Object reference not set to an instance of an object
    UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext.BuildNames () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:44)
    UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext..ctor (UnityEditor.Animations.AnimatorTransitionBase aTransition, UnityEditor.Animations.AnimatorState aSourceState, UnityEditor.Animations.AnimatorStateMachine aSourceStateMachine, UnityEditor.Animations.AnimatorStateMachine aOwnerStateMachine) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:28)
    UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.ComputeTransitionContexts () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:125)
    UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:87)
    UnityEditor.Graphs.AnimationStateMachine.AnimatorStateTransitionInspector.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorStateTransitionInspector.cs:55)


    This does not appear to be caused directly by any of my scripts - it's all in the animation portion. I have no idea what to do about it.

    I just attempted to play the scene, and the IDE crashed. I restarted, and am no longer getting that error.
     
  24. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    The reason is simple. The bottom script should not be part of your scene. Thus, you never call it and it never interact with the score game object.
     
    Mr B likes this.
  25. Sheepers

    Sheepers

    Joined:
    May 10, 2015
    Posts:
    2
    Hi - I'm new to Unity, so apologies if this is represents an oversight on my part, but I've been struggling for awhile so thought I'd see if I can get some help.

    I'm working through the Survival Shooter tutorial, and I'm at the end of the "Player Character" section (video 2), and my character doesn't turn to follow the mouse. I've confirmed that my script matches the one in the tutorial exactly (I've copy-pasted from the sample code).

    The other items in the FixedUpdate function (moving, animating) work as they should, but "Turning" doesn't do anything. I'd be happy for any suggestions on how to fix!

    thanks!
     
  26. Sheepers

    Sheepers

    Joined:
    May 10, 2015
    Posts:
    2
    Never mind, I have it fixed, my floor quad was on the wrong layer
     
    stuart69427 likes this.
  27. McThunder

    McThunder

    Joined:
    May 7, 2015
    Posts:
    4
    Hey all, so I completed the tutorial and everything works great in the editor. However, when I build the game to standalone, my enemies have no shadows...

    Any ideas what may be causing this?
     
  28. planomega

    planomega

    Joined:
    May 15, 2015
    Posts:
    1
    the first time i do the tutorial the scene goes black after the player was dead, the second time i do the tutorial i have a more brighten scene, but when i die, the screen turn darker not really black and when i build the game the enemy doesn't appear in the sixth parth of this tutorial.
     
  29. fuelafire

    fuelafire

    Joined:
    Dec 28, 2014
    Posts:
    1
    My compiler gives this error, and I've looked up references in the forums. I eventually copy/pasted the provided script from the tutorial, and still get the same response.
    https://unity3d.com/learn/tutorials/projects/survival-shooter/camera-setup

    Assets/Scripts/Camera/CameraFollow.cs(12,32): error CS0236: A field initializer cannot reference the nonstatic field, method, or property `CameraFollow.target'
     
  30. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    I have the same problem as mracey and my enemy won't attack, my damage image won't show up, and my slider doesn't do anything. I copy and pasted all of the code from the site and have the same code as mracey. I checked that nothing is missing and it still doesn't work. This is my 1st project. Help please.
    upload_2015-5-17_12-21-49.png upload_2015-5-17_12-21-21.png
     
  31. varyos

    varyos

    Joined:
    May 9, 2015
    Posts:
    1
    I got this error,help me to fix it please.
    upload_2015-5-17_22-44-53.png
    This is the script :

    using UnityEngine;

    public class GameOverManager : MonoBehaviour
    {
    public PlayerHealth playerHealth;
    public float restartDelay= 5f;


    Animator anim;
    float restartTimer

    void Awake ()
    {
    anim = GetComponent<Animator> ();
    }


    void Update()
    {
    if (playerHealth.currentHealth <= 0)
    {
    anim.SetTrigger("GameOver");

    restartTimer += Time.dealtaTime;

    if ( restartTimer >= restartDelay)
    {
    Application.LoadLevel (Application.loadedLevel);
    }
    }
    }
    }
     
  32. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    I moved on to the next step and game started working. I got to stage ten and I'm done. I am trying to play the game but this shows up:

    Assets/Scripts/Managers/GameOverManager.cs(3,14): error CS0101: The namespace `global::' already contains a definition for `GameOverManager'

    This is my script:

    using UnityEngine;

    public class GameOverManager : MonoBehaviour
    {
    public PlayerHealth playerHealth; // Reference to the player's health.
    public float restartDelay = 5f; // Time to wait before restarting the level


    Animator anim; // Reference to the animator component.
    float restartTimer; // Timer to count up to restarting the level


    void Awake ()
    {
    // Set up the reference.
    anim = GetComponent <Animator> ();
    }


    void Update ()
    {
    // If the player has run out of health...
    if(playerHealth.currentHealth <= 0)
    {
    // ... tell the animator the game is over.
    anim.SetTrigger ("GameOver");

    // .. increment a timer to count up to restarting.
    restartTimer += Time.deltaTime;

    // .. if it reaches the restart delay...
    if(restartTimer >= restartDelay)
    {
    // .. then reload the currently loaded level.
    Application.LoadLevel(Application.loadedLevel);
    }
    }
    }
    }
    Help!
     
  33. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    No, my script is this:

    using UnityEngine;

    public class GameOverManager : MonoBehaviour
    {
    public PlayerHealth playerHealth; // Reference to the player's health.
    public float restartDelay = 5f; // Time to wait before restarting the level


    Animator anim; // Reference to the animator component.
    float restartTimer; // Timer to count up to restarting the level


    void Awake ()
    {
    // Set up the reference.
    anim = GetComponent <Animator> ();
    }


    void Update ()
    {
    // If the player has run out of health...
    if(playerHealth.currentHealth <= 0)
    {
    // ... tell the animator the game is over.
    anim.SetTrigger ("GameOver");

    // .. increment a timer to count up to restarting.
    restartTimer += Time.deltaTime;

    // .. if it reaches the restart delay...
    if(restartTimer >= restartDelay)
    {
    // .. then reload the currently loaded level.
    Application.LoadLevel(Application.loadedLevel);
    }
    }
    }
    }
     
  34. Jtpoirier

    Jtpoirier

    Joined:
    May 18, 2015
    Posts:
    1
    I'm having the same problem and haven't been able to figure it out.
     
    dvdhyh likes this.
  35. DrewOfLegend

    DrewOfLegend

    Joined:
    May 18, 2015
    Posts:
    3
    Hi,

    I‘ve done this tutorial in Unity4 and it’s all worked out fine, but I’m having a lot of trouble redoing it in Unity 5. I can’t get the character to rotate with the mouse. It’s a real pain.

    Anyone else having this problem? Anyone have a solution?
     
  36. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    Evening,
    Code (CSharp):
    1. Animator anim;
    2. float restartTimer;
    3.  
    you need to add the semicolon at the end of the restartTimer declaration.
     
  37. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Hi,
    just to see if we can figure it out, this normally comes up if you have declared the GameOverManager class twice.
    what to do is, have a search to see if you have another script called GameOverManager anywhere (say in a Done folder for instance).

    if you do have a duplicate and you dont want to delete it, create a new folder in the root of the assets called, 'WebPlayerTemplates' and pop the script in there, and the editor will ignore it during compilation. just to test
     
  38. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Are you getting any errors coming up? ill have a bash at it tomorrow, been a while since ive worked through it
     
  39. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    Thanks oboshape. I did that and it worked.
     
    Last edited: May 19, 2015
    OboShape likes this.
  40. DrewOfLegend

    DrewOfLegend

    Joined:
    May 18, 2015
    Posts:
    3
    Hi again,

    I just worked out what was going wrong - embarrassingly it was all my fault (lol)
    Thanks for trying to help, I hope you’ve not wasted any time on it.
     
  41. GhostRider440

    GhostRider440

    Joined:
    May 19, 2015
    Posts:
    1
    When i got to the animation controller, all i saw was an "exit" state. No "any state" is there
     
  42. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    No worries :) glad you got it going
     
  43. JewelRay

    JewelRay

    Joined:
    Feb 15, 2015
    Posts:
    2

    you are missing a ; after float restartTimer
     
  44. JewelRay

    JewelRay

    Joined:
    Feb 15, 2015
    Posts:
    2
    I am getting an error after completing entire project. On restart of level an error is thrown " 'Player' AnimationEvent 'RestartLevel' has no receiver! Are you missing a component?" . Game restarts but the raycasting is weird. Not sure what I missed.
     
  45. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    Alt click and drag and scroll around.
     
  46. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    Now I have another error after I kill the zombunny.

    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
    UnityEngine.NavMeshAgent:SetDestination(Vector3)
    EnemyMovement:Update() (at Assets/Scripts/Enemy/EnemyMovement.cs:25)
     
  47. LeeCartwright1981

    LeeCartwright1981

    Joined:
    Apr 10, 2014
    Posts:
    1
    Hi, I'm having a problem with this tutorial where it plays fine within Unity play mode, but when I build and run it there are no enemies! I really don't understand what could be causing this.
    Any help or pointers would be greatly appreciated.

    I've just noticed that after doing the build & run, I get an error at the bottom saying "NavMesh asset format has changed. Please rebake the NavMesh data.", I rebake it but nothing changes.
     
  48. Oceankingdom

    Oceankingdom

    Joined:
    May 21, 2015
    Posts:
    3
    How did you fix this error cutesparkles1239 ?
     
  49. cutesparkles1239

    cutesparkles1239

    Joined:
    May 17, 2015
    Posts:
    8
    I did the next step and it worked.
     
    Oceankingdom likes this.
  50. Oceankingdom

    Oceankingdom

    Joined:
    May 21, 2015
    Posts:
    3
    o_O let me try :confused:
     
Thread Status:
Not open for further replies.
unityunity