Search Unity

Survival Shooter Q&A

Discussion in 'Community Learning & Teaching' started by willgoldstone, Jul 3, 2015.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This has been suggested, as we are taking it under consideration. AFAIK, Matt would love to update it.
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There is the chance that you have deleted a necessary file for the demo scene to run. The demo scene is technically part of this project and if it's missing a script, the project will fail to compile.

    You may need to re-import the project and start again, or try to find and replace the missing script.
     
  3. Reiizu

    Reiizu

    Joined:
    Apr 6, 2017
    Posts:
    6
    how could i find it?
     
  4. kisame1313

    kisame1313

    Joined:
    Mar 25, 2017
    Posts:
    8
    To be sure, create new project, go to the asset store, find Survival shooter tutorial or just visit this link. With opened new project, press open in Unity, when it opens press Download, when you downloaded it, you will see Import Unity Package window, select everything with All button and pres import.
     
  5. Chrisking01

    Chrisking01

    Joined:
    May 14, 2017
    Posts:
    4
    I started again from the beginning. It stops at the same place. But the error is different. Do you have an idea?

    Screenshot (25).png
     
  6. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    I'm a UniNoob, so take my comments with a grain a salt.
    I think your working scripts folder and the completed scripts folder are getting confused.
    Anytime an error message contains "Completed" or "Done" it is probably the case that the project's script folders are messed up.
    Your message contains the string "at Assets/_Complete-Game/Scripts/Enemy/EnemyMovement.cs"
    The scripts you are working on should be in "Assets/Scripts/Enemy/EnemyMovement.cs". There shouldn't be "_Complete-Game" in there.

    Here is my suggestion. Restart from scratch one last time. Sorry.

    We are going to physically separate the completed scripts away from your project so they cant get intermingled.
    So...
    1 Create your new Unity project.
    2 Download and import the asset from the asset store.
    3 in the "Project" tab, Go to the "Assets/_Complete-Game" directory.
    You will see Animation, MobileInput, Prefabs, Scripts, and Skyboxes.
    4a Click on Scripts (it's a directory) and move it to your desktop.
    4b Now delete it from the "Assets/_Complete-Game" directory.
    You have the directory save and sound on your desktop, but it's not in your working project now,
    and you cant get the completed scripts and working scripts intermingled now.
    5 Create the Scripts directory for your working Scripts in the Assets part of the project.
    This is where ALL of your scripts will go.

    Now, don't ever just copy any of the completed scripts from the Scripts folder that is on your desktop into your working scripts folder. They may be slightly different spelling, they may have a Namespace denoting they are complete, whatever. Use the Scripts that are in the folder that is on your desktop (the "Completed" scripts) as a reference, or if you are a little lost, but don't copy them over.

    Create each script in your working scripts folder "Assets/Scripts" and work with the script that Unity creates for you,
    e.g. "at Assets/Scripts/Enemy/EnemyMovement.cs". Note that this script, EnemyMovement.cs, is in a subfolder named "Enemy" of the Scripts folder.

    If you do want to copy paste from the completed script folder (on your desktop), just to it carefully.
    Make sure you dont copy/paste a "completed" namespace.
    Make sure you don't copy your class name with the "completed" class name unless you are sure the are spelled EXACTLY the same.

    I hope it helps Chrisking01. Once you get it working it really is a fun little project.
     
    Adam-Buckner likes this.
  7. yopunky

    yopunky

    Joined:
    Sep 1, 2014
    Posts:
    9
    @Matthew-Schell did a bit of an update based on Survival Shooter a little while back called Creating a Click to Move Game https://unity3d.com/learn/tutorials/topics/navigation/creating-click-move-game that uses Unity 5 and that particular tutorial really helped me in a couple of new areas.

    The earlier Survival Shooter tutorial video series is also great for general concepts like prefabs, animation, lighting, raycasting, navmesh agents, camera setup, UI, scoring, spawning - lots of topic areas - as a beginner you should watch this tutorial a number of times. Will Goldstone and Mike Geig did a great job with this training day tutorial. Probably why this forum thread is so long :)

    Also - a word of advice from an old coder - it is import to learn how to take some old code, perhaps with some documentation and release notices, and update it for later releases - you'll have to learn all about that with your own code soon enough. cheers.
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You would have to compare the original package with the one you are using. If you try to reimport the original package, the importer will try to import any missing files, so that's a plac to start. If that doesn't work, try reimporting into a new empty project and restarting the tutorial. Try not to move or delete any files until you're sure what you're doing.
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    What stops at the same place?

    [edit]

    Ah, I understand now...

    You should do what says:
     
    Last edited: May 18, 2017
  10. Dream5

    Dream5

    Joined:
    May 13, 2017
    Posts:
    4
    This tutorial's absolutely fantastic and everything working for me apart from one small issue? (Few fixes in the YouTube comments, alongside the PDF included in the project). Enemy movement and gun damage works in the project view, but not when the game is built. I've updated the assets too and I have no errors but the fluffy monsters just don't move. Also the gun isn't dishing out damage when the project is built and run. This also occurs with the complete game scene.
     
  11. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    If you didnt have all of the enemies in your working prefabs folder and so simply copied the missing prefabs from the "completed" folder you may have a problem.

    delete the ones you copied and try either

    a) BuckBuchanan soln at post #545
    https://forum.unity3d.com/threads/survival-shooter-q-a.338190/page-11#post-2962342

    or
    b) import the missing prefab assets from the _Complete-Game folder
    https://forum.unity3d.com/threads/survival-shooter-q-a.338190/page-12#post-3050955

    This assumes you copied missing prefabs from the "completed" folder.
    Hope this helps
     
  12. ParanormalRuffian

    ParanormalRuffian

    Joined:
    May 16, 2017
    Posts:
    1
    Hello, my enemy manager is not working. I have my prefabs in the correct place.
    Here is my code

    using UnityEngine;

    public class EnemySpawning : MonoBehaviour
    {
    public PlayerHealth playerHealth;
    public GameObject enemy;
    public float spawnTime = 3f;
    public Transform[] spawnPoints;


    void Start ()
    {
    InvokeRepeating ("Spawn", spawnTime, spawnTime);
    }


    void Spawn ()
    {
    if(playerHealth.currentHealth <= 0f)
    {
    return;
    }

    int spawnPointIndex = Random.Range (0, spawnPoints.Length);

    Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    }
    }

    Please help! :)
     
    Dream5 likes this.
  13. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    I'm not sure, your "EnemySpawning" class is similar to my "EnemyManager" class. I honestly don't remember this tutorial well enough to know if this is correct or not...
    Here is my EnemyManager.cs script:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. public class EnemyManager : MonoBehaviour
    4. {
    5.     public PlayerHealth playerHealth;
    6.     public GameObject enemy;
    7.     public float spawnTime = 3f;
    8.     public Transform[] spawnPoints;
    9.  
    10.     void Start ()
    11.     {
    12.         InvokeRepeating ("Spawn", spawnTime, spawnTime);
    13.     }
    14.  
    15.  
    16.     void Spawn()
    17.     {
    18.         GameObject[] n = GameObject.FindGameObjectsWithTag("Shootable");
    19.         if (n.Length >= playerHealth.maxEnemies) return;
    20.  
    21.         if (playerHealth.currentHealth <= 0f)
    22.         {
    23.             return;
    24.         }
    25.  
    26.         int spawnPointIndex = Random.Range (0, spawnPoints.Length);
    27.         Instantiate (enemy, spawnPoints[spawnPointIndex].position, spawnPoints[spawnPointIndex].rotation);
    28.     }
    29. }
    30.  
     
  14. Dream5

    Dream5

    Joined:
    May 13, 2017
    Posts:
    4
    Thanks for your response, but like I said in the post. Even the complete game doesn't build correctly. :c
     
  15. laboratoriosies

    laboratoriosies

    Joined:
    May 20, 2017
    Posts:
    2
    Hello!
    I need some help. I'm following the tutorial, and, in Chapter 3, regarding of the camera, everytime I press Play, my whole game window becomes completely black.
    Someones knows what is happening? Thanks!
     

    Attached Files:

  16. Dream5

    Dream5

    Joined:
    May 13, 2017
    Posts:
    4
    The camera position isn't right :)

    X: 1
    Y: 15 (Not minus)
    Z: -22
     
    laboratoriosies likes this.
  17. laboratoriosies

    laboratoriosies

    Joined:
    May 20, 2017
    Posts:
    2
    Thanks! It was something also with the script, that changed the position of the camera. I rewrite everything and now works. Thanks again!
     
  18. Beolisa

    Beolisa

    Joined:
    May 14, 2017
    Posts:
    2
    Hi everyone, I am a newbie of Unity and I am doing survival shooting with 5.5.2f1. After finishing the 10th phase, everything is working fine but this error has kept popping up:

    'Zombunny 1(Clone)' AnimationEvent 'NewEvent' has no receiver! Are you missing a component?

    'ZomBear 1(Clone)' AnimationEvent 'NewEvent' has no receiver! Are you missing a component?

    'Player' AnimationEvent 'RestartLevel' has no receiver! Are you missing a component?

    I am sure that my script is correct because I only copied and pasted the script from the internet. I already followed some suggestion:

    https://forum.unity3d.com/threads/p...-receiver-are-you-missing-a-component.307523/

    Like, uncheck the Optimize Game object. Or trying to delete the event in Events panel but there are not any events in there.
    What do I do now? Any suggestion? Please tell me if you need any extra informations
    Thanks
     
  19. SeekingMan

    SeekingMan

    Joined:
    May 25, 2017
    Posts:
    1
    Hello. I am also working on the Survival Shooter game with the tutorial.
    I have come across a problem that I cannot fix. I saw it near the end of the second video.

    The idle and walking animations for the player's model does now work. However, the player's gun does animate.
    The entire player model itself is able to move and rotate.
    I even have "has exit time" unchecked.
    Screen Shot 2017-05-25 at 10.05.14 AM.png
    From these two pictures, the character is moving and the gun is bouncing. I was told to have the idle animation transition into itself but that did nothing.
    Also, the script perfectly matches the video.

    Previewing the animations in the Controller from the inspector shows no animation as well.
    Screen Shot 2017-05-25 at 10.10.40 AM.png
    I'm sorry if this is overwhelming with information.
    Can anyone help?
     

    Attached Files:

  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Perhaps @peteorstrike might know more than I do...
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please use code tags when posting code on the forums:

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is usually because you do not have a working camera in the scene. You can tell by searching for "camera" in the hierarchy. If this does not reveal anything you can try to search for the camera "Type" or the camera "Component" on a GameObject by picking the "Type" in the drop down any typing "camera".

    Screenshot 2017-06-01 13.05.24.png

    If you don't have a camera, please restart the tutorial, as you may have missed a critical step.

    [Edit] Sorry, didn't look at the image. @Dream5 is correct.
     
  23. Zhavina

    Zhavina

    Joined:
    May 24, 2017
    Posts:
    1
    Hello there !

    I'm really new to Unity and C#, I've learned a lot with your tutorials.
    I just finished the Survival Shooter game, everything went well and now I try to change some specifies so the game is more like I would it to be :p

    I want would the health UI to dsiplay health by number insteand of a slider, and there comes the troubles, lol.
    I don't why and where I'm wrong, but the 'currentHealth' wont show up in the game.

    Here's my code (The french comments are just for me ^^):

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4. using UnityEngine.SceneManagement;
    5.  
    6.  
    7. public class PlayerHealth : MonoBehaviour
    8. {
    9.     public int startingHealth = 100;
    10.     public int currentHealth;
    11. //    public Slider healthSlider;
    12.  
    13.     public Text healthText;
    14.  
    15.     public Image damageImage;
    16.     public AudioClip deathClip;
    17.     public float flashSpeed = 5f;
    18.     public Color flashColour = new Color(1f, 0f, 0f, 0.1f);
    19.  
    20.     Animator anim;
    21.     AudioSource playerAudio;
    22.     PlayerMovement playerMovement;
    23.     PlayerShooting playerShooting;
    24.     bool isDead;
    25.     bool damaged;
    26.  
    27.  
    28.     void Awake ()
    29.     {
    30.         anim = GetComponent <Animator> ();
    31.         playerAudio = GetComponent <AudioSource> ();
    32.         playerMovement = GetComponent <PlayerMovement> (); //Permet de faire appel au script 'PlayerMovement' sur le gameObject où est attaché ce script.
    33.         playerShooting = GetComponentInChildren <PlayerShooting> ();
    34.         currentHealth = startingHealth;
    35.         healthText.text = "vie : " + startingHealth; //Here,even at the start, startingHealth won't show up.
    36.     }
    37.  
    38.  
    39.     void Update ()
    40.     {
    41.         if(damaged)
    42.         {
    43.             damageImage.color = flashColour;
    44.         }
    45.         else
    46.         {
    47.             damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
    48.         }
    49.         damaged = false;
    50.     }
    51.  
    52.  
    53.     public void TakeDamage (int amount) //Fonction qui sera utilisé dans le script EnemyAttack.
    54.     {
    55.         damaged = true;
    56.  
    57.         currentHealth -= amount;
    58.  
    59.         healthText.text = "vie : " + currentHealth; //And there, currentHealth doesn't appear :(
    60. //        healthSlider.value = currentHealth;
    61.  
    62.         playerAudio.Play ();
    63.  
    64.         if(currentHealth <= 0 && !isDead)
    65.         {
    66.             Death ();
    67.         }
    68.     }
    69.  
    70.  
    71.     void Death ()
    72.     {
    73.         isDead = true;
    74.  
    75.         playerShooting.DisableEffects ();
    76.  
    77.         anim.SetTrigger ("Die");
    78.  
    79.         playerAudio.clip = deathClip; //On remplace l'AudioClip de L'AudioSource par le deathClip que l'on a choisis dans Unity.
    80.         playerAudio.Play ();
    81.  
    82.         playerMovement.enabled = false;
    83.         playerShooting.enabled = false;
    84.     }
    85. }
    Of course, I put in the public text in Unity, the text component that I want to change.

    Thanks for your help !
     

    Attached Files:

  24. GoViInAHole

    GoViInAHole

    Joined:
    Jun 4, 2017
    Posts:
    1
    So I built my game but when I die and the game reloads, my lights turn off and the game turns completely dark. This would be fine if it applied to all attempts but it only happens after my first death and then on every death after that. I just want one lighting for all level attempts, wether it be dark or light.
    Normal:
    upload_2017-6-4_12-51-7.png
    Dark:
    upload_2017-6-4_12-51-59.png
    As I said above, it changes to this lighting after dying once, and then it stays like this until I stop the game and press play again. Please help, and thanks in advance.
     
    atrajano likes this.
  25. carlo_montoya

    carlo_montoya

    Joined:
    Jun 4, 2017
    Posts:
    5
    Attached image where you will find the Event.
     

    Attached Files:

  26. muhnaufal

    muhnaufal

    Joined:
    Jun 4, 2017
    Posts:
    1
    Hello everyone,
    I have a problem in tutorial no. 4
    The problem is my Zombunny does not follow my players and just moves in place. How to handle it?
    i'm pretty sure that there is no problem on my script
    My settings :
    Agent Radius = 0.75
    Agent Height = 1.2
    Max Slope= 36.2 (Before is 45 but unity warns it so i changed it)
    Step Height= 0.34
    Voxel Size=0.25

    please
    (I'm using unity version 5.3.8 f1)
     
    Last edited: Jun 7, 2017
  27. TGKG

    TGKG

    Joined:
    Dec 31, 2014
    Posts:
    180
    Trying to work with the
    Integrating Unity IAP In Your Game tutorial which uses the Survival Shooter demo.
    I followed all of the instructions here for the Survival shooter IAP demo. The game works fine and the IAP works fine from inside the Unity Editor. However I cannot get the project to build. I have tried to build as a PC version build and as an android build. Both get the same error.
    I am running with Unity version 5.5.1f1
    The error message below is confusing:
    "Assets/IAPDemo/Scripts/WeaponShop/MakeWeaponObject.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?"

    It is confusing because there actually is a "using UnityEditor;" statement in the MakeWeaponObject.cs as shown below

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4.  
    5. public class MakeWeaponObject {
    6.  
    7.     [MenuItem("Assets/Create/Weapon Object")]
    8.     public static void CreateWeaponObject()
    9.     {
    10.         WeaponObject asset = ScriptableObject.CreateInstance<WeaponObject> ();
    11.  
    12.         AssetDatabase.CreateAsset (asset, "Assets/NewWeaponObject.asset");
    13.         AssetDatabase.SaveAssets ();
    14.         EditorUtility.FocusProjectWindow ();
    15.         Selection.activeObject = asset;
    16.  
    17.     }
    18. }
    19.  
    Why won't this tutorial build??
     
  28. smatsah

    smatsah

    Joined:
    Jun 6, 2017
    Posts:
    2

    Hey.. So i am having the same problem right now and i tried your way, i checked that all the Navigation Static boxes in all Base, Planks, and Sides.. But the ZomBunnies are still stuck their over each other. Any other solutions?
    Also, they keep multiplying in their place, but once the player is close it them they scatter around the point, pushing each other!
     
  29. Mecha11

    Mecha11

    Joined:
    Jun 12, 2017
    Posts:
    1
    Just finished phase 10 (This error was occuring in phase 9, but I decided to ignore it for a bit), and my zombear and hellephant arent moving or attacking. I just get this error;
    NullReferenceException: Object reference not set to an instance of an object
    CompleteProject.EnemyMovement.Update () (at Assets/_Complete-Game/Scripts/Enemy/EnemyMovement.cs:27)
     
  30. whencut999

    whencut999

    Joined:
    Jun 9, 2017
    Posts:
    2
    sir i a newbie

    i stuck in the 7th chapter harming enemies

    i get this error when i try to shoot enemies with player

    LineRenderer.SetPosition index out of bounds!
    UnityEngine.LineRenderer:SetPosition(Int32, Vector3)
    PlayerShooting:Shoot() (at Assets/Scripts/Player/PlayerShooting.cs:85)
    PlayerShooting:Update() (at Assets/Scripts/Player/PlayerShooting.cs:39)


    plz help me solve this error i have serched many forum threds but did not find the solution plz help me solve this
     
  31. atrajano

    atrajano

    Joined:
    Jun 10, 2017
    Posts:
    4
    I solved this just now by going to Window -> Light -> Settings and removing the default skybox.
     
    Last edited: Jun 17, 2017
  32. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    I have the same problem, so I tried your fix. Unfortunately, my scene now defaults to the "dark scene" that I get when the game restarts. With your solution, at least the lighting is consistent, but I'd like to have the starting colour to be the default. Has anyone been able to fix this?
     
  33. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Anytime an error message contains "Completed" , "_Complete-Game" or "Done" it is probably the case that the project's script folders are messed up.

    Please take a look at post 606 near the top of this page
     
  34. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    @Mecha11, you may have the same problem that I had. When I downloaded the asset package from the Unity Store, I didn't have prefabs for ZomBear or Hellephant, although in the tutorial the say you do. I copied the prefabs from the _Completed-Game folder without realizing that the scripts are different in that folder. If this is what you did, then go the prefab for ZomBear and Hellephant and delete the scripts EnemyMovement, EnemyAttack and EnemyHealth. Then add these three scripts back in but use the scripts that you developed in the tutorial.

    Hope this helps.
     
  35. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    I have this problem too. I tried build the game and running the exe and it works perfectly. For me, therefore, the lighting problem is only in the editor.
     
  36. GoldProductions

    GoldProductions

    Joined:
    Jun 23, 2017
    Posts:
    1
    I Dont Have A Scenes Folder
     
  37. Rezyaev

    Rezyaev

    Joined:
    May 23, 2017
    Posts:
    4
    Hello everybody. I have a small qustion. What does this line of code mean?
    Code (CSharp):
    1. Time.timeScale = Time.timeScale == 0 ? 1 : 0;
     
  38. Ben_Iyan

    Ben_Iyan

    Joined:
    May 13, 2016
    Posts:
    204
    The first = is the assignment operator, so you need to look at the right hand side first. The ? is a shorthand notation for an "if" statement. Therefore, you read the code as:

    Code (CSharp):
    1. if (Time.timeScale == 0)
    2. {
    3.     Time.timeScale = 1; //First value after the ?
    4. }
    5. else
    6. {
    7.     Time.timeScale = 0; //Second value after the ?
    8. }
     
  39. mattvarmo

    mattvarmo

    Joined:
    Jun 26, 2017
    Posts:
    1
    Hello, Thank you for the tutorial is very easy to follow and is well explained but I have a problem that is not in the pdf guide and the video, in the Spawning Enemies video at the begining he say that I have to drag the EnemyAC from Prefabs to the Zombear, who is in the Project secction, I select the Zombear and when I try to drag and drop de EnemyAC to de Animator of Zombear in the Inspector I can't, the Animator zone in the inspector of Zombear appears in a grey color, I can't select or change anything in there. This only is possible if I put the Zombear on the Hierarchy or the scene, but thats not the way that they do in the video. The PDF say "no know issues" So, What can I do?

    P.D: Sorry if there's an error or if is not understandable, English is not my first language, I hope you can understand.

    P.D. 2: Hi, I already find a solution, for the moment work but I don't know if this is correct so if anybody think that is wrong please tell me, what I did was drag the Zombear to the Hierarchy and then to the Prefabs folder on the Project, Now nothing is grey on the inspector and I can drag the EnemyAC.
     
    Last edited: Jun 26, 2017
  40. atrajano

    atrajano

    Joined:
    Jun 10, 2017
    Posts:
    4
    You can go to the Lights gameobject group and in there is a Scene Lighting you can change the intensity to 1 to make it much brighter. Or 0.5 to be a bit gloomier but not too dark.
     
    Last edited: Jun 28, 2017
  41. whencut999

    whencut999

    Joined:
    Jun 9, 2017
    Posts:
    2
    i stuck in the 7th chapter harming enemies

    i get this error when i try to shoot enemies with player

    LineRenderer.SetPosition index out of bounds!
    UnityEngine.LineRenderer:SetPosition(Int32, Vector3)
    PlayerShooting:Shoot() (at Assets/Scripts/Player/PlayerShooting.cs:85)
    PlayerShooting:Update() (at Assets/Scripts/Player/PlayerShooting.cs:39)


    plz help me solve this error i have serched many forum threds but did not find the solution plz help me solve this
     
  42. TH3B3AST

    TH3B3AST

    Joined:
    Dec 6, 2016
    Posts:
    1
    I picked enemy from complete game folder but it wont follow any helps pls?
     
  43. AnthGrad

    AnthGrad

    Joined:
    Jun 10, 2017
    Posts:
    2
    Hello there,

    I'm new to Unity (and coding in general) :p but have made it through the excellent Shooter tutorial, with the exception of a few errors stemming from the GameOverManager script.

    Below is my code. What have I done wrong? Any help is very appreciated!

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class GameOverManager : MonoBehaviour
    4. {
    5.     public PlayerHealth playerHealth;       // Reference to the player's health.
    6.     public float restartDelay = 5f;
    7.  
    8.  
    9.     Animator anim;                          // Reference to the animator component.
    10.     float restartTimer;                     // Timer to count up to restarting the level
    11.  
    12.     void Awake ()
    13.     {
    14.         anim = GetComponent <Animator> ();
    15.     }
    16.  
    17.  
    18.     void Update ()
    19.  
    20.     {
    21.         if (playerHealth.currentHealth <= 0)
    22.     }
    23.  
    24.         {
    25.             anim.SetTrigger ("GameOver");
    26.  
    27.             RestartTimer += Time.deltaTime;
    28.  
    29.             if (RestartTimer >= RestartDelay)
    30.     }
    31.  
    32.     public void RestartLevel ()
    33.     {
    34.         SceneManager.LoadScene (0);
    35.     }
    36. }
     
  44. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    It looks like you have a misplaced curly bracket.
    Remove the } at line 22 and add back in after line 29.

    And there is a problem with line 29
    if (RestartTimer >= RestartDelay)

    There must be something you want to do if it's true (or if it's not)?

    so....
    Code (csharp):
    1.  
    2.     using UnityEngine;
    3.      
    4.     public class GameOverManager : MonoBehaviour
    5.     {
    6.         public PlayerHealth playerHealth;       // Reference to the player's health.
    7.         public float restartDelay = 5f;
    8.      
    9.      
    10.         Animator anim;                          // Reference to the animator component.
    11.         float restartTimer;                     // Timer to count up to restarting the level
    12.      
    13.         void Awake ()
    14.         {
    15.             anim = GetComponent <Animator> ();
    16.         }
    17.      
    18.      
    19.         void Update ()
    20.         {
    21.             if (playerHealth.currentHealth <= 0)
    22.              {
    23.                 anim.SetTrigger ("GameOver");
    24.                 RestartTimer += Time.deltaTime;
    25.                 if (RestartTimer >= RestartDelay)
    26.                  {
    27.                      RestartLevel();    // perhaps this is want you want to do????
    28.                   }
    29.              }
    30.         }
    31.      
    32.  
    33.         public void RestartLevel ()
    34.         {
    35.             SceneManager.LoadScene (0);
    36.         }
    37.  
    38.  
    39.     }
    40.  
     
  45. AnthGrad

    AnthGrad

    Joined:
    Jun 10, 2017
    Posts:
    2
    Thank you gwnguy!

    I'll give this a try.


     
  46. ApocFI

    ApocFI

    Joined:
    May 26, 2017
    Posts:
    33
    Edit: Solved it myself. I'll leave it here for others with similar problems :)

    I'm doing this tutorial second time, this time using my own assets. I'm having trouble with the shooting mechanism. The shot mechanism works, but the line renderer is sometimes directed to completely wrong direction (starts when I hit the target), and the hit particles aren't being displayed. The error I get is:
    NullReferenceException: Object reference not set to an instance of an object
    EnemyHealth.TakeDamage (Int32 amount, Vector3 hitPoint) (at Assets/Scripts/Enemy/EnemyHealth.cs:49)
    PlayerShooting.Shoot () (at Assets/Scripts/Player/PlayerShooting.cs:91)
    PlayerShooting.Update () (at Assets/Scripts/Player/PlayerShooting.cs:40)

    Assets/Scripts/Enemy/EnemyHealth.cs:49):
    Code (CSharp):
    1. hitParticles.transform.position = hitPoint;
    Assets/Scripts/Player/PlayerShooting.cs:91):
    Code (CSharp):
    1. enemyHealth.TakeDamage (damagePerShot, shootHit.point);
    Assets/Scripts/Player/PlayerShooting.cs:40):
    Code (CSharp):
    1. Shoot ();
    I've searched and found some similar cases, but haven't figured it out by myself yet. Any ideas? I've been able to find previous NullReferenceExceptions on my own, but this one I can't seem to tackle on my own :/

    Edit: The problem was I had not assigned the hitparticles to the enemy. Once assigned, the line renderer behaved as expected.
     
    Last edited: Jul 5, 2017
  47. SilverKrystel

    SilverKrystel

    Joined:
    Jul 7, 2017
    Posts:
    1
    I also had that issue, but I solved it by just clearing the console. It only ever came up once.
     
  48. kajes

    kajes

    Joined:
    Jun 25, 2017
    Posts:
    6
    I ran into this problem as well and found that the "Has Exit Time" checkbox was checked on transitions. Unchecking that in both Idle->Move and Move->Idle worked for me, but judging by your screenshots you don't seem to have it checked anyway.

    Also noticing that your post is pretty old by now. Did you manage to solve it already?
     
    R3ps4c and AeroshopGraphic like this.
  49. littleraindrop

    littleraindrop

    Joined:
    Jul 13, 2017
    Posts:
    1
    I have the code copy down exactly and I went through to make sure that no errors or spelling has occur, but the problem is I can't seem to be turning with my mouse. The same problem as @midomady304 for the Survival Shooter.
     
    imcheney likes this.
  50. ludancv

    ludancv

    Joined:
    Jul 13, 2017
    Posts:
    1
    Hi,
    I have an issue, I imported the assests from the store, everithing was fine but then my unity crashed, when I restarted the eviroment was all withe, I check the materials folder and they were buggy so I downloaded the assests again but is the same result, anybody knows how to fix this?