Search Unity

Survival Shooter Q&A

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

  1. jake-tyerman

    jake-tyerman

    Joined:
    Jul 15, 2017
    Posts:
    1
    Newbie here, so forgive me if I'm extremely oblivious to the solution.

    I dragged the PlayerMovement script into the Player GameObject only to learn that I have to fix compile errors. I'm using Unity 5.5.2f1 and I don't recall editing the scripts at all after importing the package. Is this because i'm using a newer version of Unity with an older asset package? Thanks.
     
  2. NewbieJD

    NewbieJD

    Joined:
    Jul 15, 2017
    Posts:
    2
    New to all this so please excuse my ignorance. I've successfully built the game but need to expand the size of the level. I've duplicated the floor element in the environment and placed it alongside the existing one. I've then expanded the LevelExtent boundaries so that the player can move between the two floor objects. However, the enemies cannot move outside of the original floor space. What have I missed? Clearly there's something limiting the enemy's movement but I can't seem to pin down what it is? Thanks!
     
  3. Kainatic

    Kainatic

    Joined:
    May 31, 2017
    Posts:
    5
    You need to create one in the root of the assets folder.
     
  4. renedon

    renedon

    Joined:
    Jul 14, 2017
    Posts:
    5
    In Zombunny Death(), the capsuleCollider is changed to a trigger collider, so the player doesn't bump into it anymore.

    Code (CSharp):
    1. capsuleCollider.isTrigger = true;
    Why isn't the capsuleCollider just set to disabled? Wouldn't that be more accurate, to turn off the collider component.
     
  5. JoniBerg

    JoniBerg

    Joined:
    Jun 30, 2017
    Posts:
    14
    Code (CSharp):
    1.  
    2.  
    3. public float AttackDamage;
    4.  
    5. void Update()
    6.     {
    7.         timer += Time.deltaTime;
    8.  
    9.         {
    10.             if (timer >= TimeBetweenAttacks && PlayerInRange && EnemYHealtH.CurrentHealth > 0)
    11.             {
    12.                 Attack ();
    13.             }
    14.  
    15.             if (PlayeRHealtH.CurrentHealth <= 0)
    16. {
    17.                 Anim.SetTrigger ("PlayerDeath");
    18.             }
    19.  
    20.         }
    21.  
    22.     }
    23.    
    24. void Attack ()
    25.  
    26.     {
    27.         timer = 0f;
    28.  
    29.         if (PlayeRHealtH.CurrentHealth > 0)
    30.         {
    31.             PlayeRHealtH.TakeDamage (AttackDamage);
    32.         }
    33.  
    34.     }
    35.  
    36.  
    My "AttackDamage" variable is problem for Unity... Why?

    In Console message is: "EnemyAttack.cs(xx,xx): error CS1501: No overload for method `TakeDamage' takes `1' arguments"
     
    Last edited: Jul 22, 2017
  6. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144

    In my case, my code for the method TakeDamage has one integer argument:
    Code (csharp):
    1.  
    2.     public void TakeDamage (int amount)
    3.     {
    4. ....
    5.  
    6.  
    Perhaps your problem is that you are calling with a float?
     
  7. JoniBerg

    JoniBerg

    Joined:
    Jun 30, 2017
    Posts:
    14
    Yeah that is my problem but what is solved this?
     
  8. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    C# (most programming languages) have basic data types, such as integer, float, boolean, string, and others. The computer stores them differently, and they cant be interchanged.

    When you defined your method, you said the computer should see an interger (in this case, it is an integer named amount)
    public void TakeDamage (int amount)

    When you called your method, you told the computer to use a float (in this case, it is a float named AttackDamage)
    PlayeRHealtH.TakeDamage (AttackDamage);
    which you told the computer would be a float in line 3
    public float AttackDamage;

    You can "cast" (convert) one data type to another. Googling "How can I convert float to int" yields this example:
    float z = 5.123f;
    int a = (int) z;

    You can cast a float to an int by using (int)
    Thus, in your case, you could have written
    PlayeRHealtH.TakeDamage ((int)AttackDamage);


    Note a side effect of integer vs float is the precision of a value.
    The float values of 1.12 and 1.32 when cast to integer will both be 1

    The issues of data types is interesting. It goes beyond the basic data types and into more complex (user defined) types.
    You will see them in Unity if you try to use a basic data type (like float) where Unity wants to see a complex data type, for example Vector3.
    Vector3 is a complex (user defined) data type that is made up of 3 floats. You will see an error message when you have improper data types.
     
  9. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Addendum to message #658 above:

    Different methods with same name can be called based on arguments passed.

    Try this:
    Code (csharp):
    1.  
    2.     void Start()
    3.     {
    4.         // Demonstrate overloading of a method, how different methods with same name can be called based on arguments passed
    5.         // In the example, we'll define a method named MethodExample  which will be uniquely identified by the arguments passed to it
    6.         MethodExample();
    7.         MethodExample(1);
    8.         MethodExample(2f);
    9.         MethodExample(true);
    10.         MethodExample("Hello World");
    11.         MethodExample(6, 66f);
    12.         // *** I am commented out ****   MethodExample(6, 66, 666);
    13.     }
    14.     public void MethodExample()
    15.     {
    16.         Debug.Log("MethodExample: no arguments.");
    17.     }
    18.     public void MethodExample(int i)
    19.     {
    20.         Debug.Log("MethodExample: one integer i="+i);
    21.     }
    22.     public void MethodExample(float a)
    23.     {
    24.         Debug.Log("MethodExample: one float a=" + a);
    25.     }
    26.     public void MethodExample(bool b)
    27.     {
    28.         Debug.Log("MethodExample: one boolean b=" + b);
    29.     }
    30.     public void MethodExample(string txt)
    31.     {
    32.         Debug.Log("MethodExample: one string txt=" + txt);
    33.     }
    34.     public void MethodExample(int i, float a)
    35.     {
    36.         Debug.Log("MethodExample: one integer i=" + i+ " and one float a=" + a);
    37.     }
    38.  
    39.  
    When you run it check the console log.

    Now, go back and uncomment line 12. You are now trying to call a version of MethodExample that has three integer arguments. Here's the error message:
    Error CS1501 No overload for method 'MethodExample' takes 3 arguments MyJoystick I:\programs\Unity Projects\MyJoystick\Assets\Scripts\myController.cs 45 Active

    Thats the precise reason your code had the problem you reported- and why fixing the data type fixed the error
     
    Last edited: Jul 23, 2017
  10. Molten-Path

    Molten-Path

    Joined:
    Jul 17, 2017
    Posts:
    1
    Hi, so i'm new to Unity and i decide to start by following this tutorial, and i've encountered some problems, i've followed until the 6th Chapter:
    1. my character can shoot the zombunny, but it seems the bunny isn't hurt at all
    my EnemyHealth Script

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class EnemyHealth : MonoBehaviour
    4. {
    5.     public int startingHealth = 100;
    6.     public int currentHealth;
    7.     public float sinkSpeed = 2.5f;
    8.     public int scoreValue = 10;
    9.     public AudioClip deathClip;
    10.  
    11.  
    12.     Animator anim;
    13.     AudioSource enemyAudio;
    14.     ParticleSystem hitParticles;
    15.     CapsuleCollider capsuleCollider;
    16.     bool isDead;
    17.     bool isSinking;
    18.  
    19.  
    20.     void Awake ()
    21.     {
    22.         anim = GetComponent <Animator> ();
    23.         enemyAudio = GetComponent <AudioSource> ();
    24.         hitParticles = GetComponentInChildren <ParticleSystem> ();
    25.         capsuleCollider = GetComponent <CapsuleCollider> ();
    26.  
    27.         currentHealth = startingHealth;
    28.         Debug.Log("Health check");
    29.     }
    30.  
    31.  
    32.     void Update ()
    33.     {
    34.         if(isSinking)
    35.         {
    36.             transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
    37.         }
    38.     }
    39.  
    40.  
    41.     public void TakeDamage (int amount, Vector3 hitPoint)
    42.     {
    43.         Debug.Log("Hit Check");
    44.         if (isDead)
    45.             return;
    46.  
    47.         enemyAudio.Play ();
    48.  
    49.         currentHealth -= amount;
    50.            
    51.         hitParticles.transform.position = hitPoint;
    52.         hitParticles.Play();
    53.  
    54.         if(currentHealth <= 0)
    55.         {
    56.             Death ();
    57.         }
    58.         Debug.Log("Damaged");
    59.     }
    60.  
    61.  
    62.     void Death ()
    63.     {
    64.         isDead = true;
    65.  
    66.         capsuleCollider.isTrigger = true;
    67.  
    68.         anim.SetTrigger ("Dead");
    69.  
    70.         enemyAudio.clip = deathClip;
    71.         enemyAudio.Play ();
    72.     }
    73.  
    74.  
    75.     public void StartSinking ()
    76.     {
    77.         GetComponent <UnityEngine.AI.NavMeshAgent> ().enabled = false;
    78.         GetComponent <Rigidbody> ().isKinematic = true;
    79.         isSinking = true;
    80.         //ScoreManager.score += scoreValue;
    81.         Destroy (gameObject, 2f);
    82.     }
    83. }
    My PlayerShooting Script

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerShooting : MonoBehaviour
    4. {
    5.     public int damagePerShot = 20;
    6.     public float timeBetweenBullets = 0.15f;
    7.     public float range = 100f;
    8.  
    9.  
    10.     float timer;
    11.     Ray shootRay = new Ray();
    12.     RaycastHit shootHit;
    13.     int shootableMask;
    14.     ParticleSystem gunParticles;
    15.     LineRenderer gunLine;
    16.     AudioSource gunAudio;
    17.     Light gunLight;
    18.     float effectsDisplayTime = 0.2f;
    19.  
    20.  
    21.     void Awake ()
    22.     {
    23.         shootableMask = LayerMask.GetMask ("Shootable");
    24.         gunParticles = GetComponent<ParticleSystem> ();
    25.         gunLine = GetComponent <LineRenderer> ();
    26.         gunAudio = GetComponent<AudioSource> ();
    27.         gunLight = GetComponent<Light> ();
    28.     }
    29.  
    30.  
    31.     void Update ()
    32.     {
    33.         timer += Time.deltaTime;
    34.  
    35.         if(Input.GetButton ("Fire1") && timer >= timeBetweenBullets && Time.timeScale != 0)
    36.         {
    37.             Shoot ();
    38.         }
    39.  
    40.         if(timer >= timeBetweenBullets * effectsDisplayTime)
    41.         {
    42.             DisableEffects ();
    43.         }
    44.     }
    45.  
    46.  
    47.     public void DisableEffects ()
    48.     {
    49.         gunLine.enabled = false;
    50.         gunLight.enabled = false;
    51.     }
    52.  
    53.  
    54.     void Shoot ()
    55.     {
    56.         timer = 0f;
    57.  
    58.         gunAudio.Play ();
    59.  
    60.         gunLight.enabled = true;
    61.  
    62.         gunParticles.Stop ();
    63.         gunParticles.Play ();
    64.  
    65.         gunLine.enabled = true;
    66.         gunLine.SetPosition (0, transform.position);
    67.  
    68.         shootRay.origin = transform.position;
    69.         shootRay.direction = transform.forward;
    70.  
    71.         if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
    72.         {
    73.             EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
    74.             if (enemyHealth != null)
    75.             {
    76.                 Debug.Log("Damage deal");
    77.                 enemyHealth.TakeDamage (damagePerShot, shootHit.point);
    78.                 Debug.Log("Damage Check");
    79.             }
    80.             gunLine.SetPosition (1, shootHit.point);
    81.         }
    82.         else
    83.         {
    84.            
    85.             gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
    86.         }
    87.     }
    88. }
    The Debug log show "health check", but missing the "hit check", "damage deal" and "damage check", is there something i miss/do wrong??

    2. it seems that the line i fire is a little bit miss directed, how do i fix it?? (image attached)

    Otherwise it's a great tutorial and i've learned many things. Thank you
     

    Attached Files:

  11. JoniBerg

    JoniBerg

    Joined:
    Jun 30, 2017
    Posts:
    14
    My Score points not working



    Death term on Enemyhealth script:
    Code (CSharp):
    1.  
    2.  
    3. public int ScoreValue = 20;
    4.  
    5. // if enemy is death...
    6.         void Death ()
    7.  
    8.         {
    9.             isDead = true;
    10.  
    11.             Anim.SetTrigger ("Dead");
    12.  
    13.             //ScoreManager.Score += ScoreValue;
    14.             // Adding score points...
    15.             ScoreManager.Score = ScoreManager.Score = ScoreValue;
    16.  
    17.  
    18.             CapCollider.isTrigger = true;
    19.      
    20.             EnemyAudio.clip = DeathClip;
    21.             EnemyAudio.Play();
    22.          
    23.             Destroy (gameObject, 2f);
    24.         }
    25.  

    ScoreManader Script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class ScoreManager : MonoBehaviour
    6. {
    7.  
    8.     public static int Score;
    9.     public Text ScoreText;
    10.  
    11.     // Use this for initialization
    12.     void Awake ()
    13.     {
    14.         ScoreText = GetComponent<Text> ();
    15.         Score = 0;
    16.     }
    17.  
    18.     // Adding Score points.
    19.     void Scoreadding ()
    20.     {
    21.         ScoreText.text = "Score: " + Score;
    22.     }
    23. }
    24.  
     
  12. GameyMakey

    GameyMakey

    Joined:
    Jul 24, 2017
    Posts:
    1
    hi,
    I am having trouble with the zombunny. It is not following the player an its just staying still.
    Please help me.
     
  13. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    change line 15
    from
    ScoreManager.Score = ScoreManager.Score = ScoreValue;
    to
    ScoreManager.Score = ScoreManager.Score + ScoreValue;
     
    Last edited: Jul 24, 2017
  14. JoniBerg

    JoniBerg

    Joined:
    Jun 30, 2017
    Posts:
    14
    Don't working still. My Score HUD shows only my Scoretext text "Score: " not adding 20 points after : on bunny is death... So this both scripts maybe working.


    Code (CSharp):
    1. // if enemy is death...
    2.         void Death ()
    3.  
    4.         {
    5.             isDead = true;
    6.  
    7.             Anim.SetTrigger ("Dead");
    8.  
    9.  
    10.             // Adding score points...
    11.             ScoreManager.Score = ScoreManager.Score + ScoreValue;
    12.        
    13.             CapCollider.isTrigger = true;
    14.    
    15.             EnemyAudio.clip = DeathClip;
    16.             EnemyAudio.Play();
    17.        
    18.             Destroy (gameObject, 2f);
    19.         }
    20.  
    21.  
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class ScoreManager : MonoBehaviour
    6. {
    7.  
    8.     public static int Score;
    9.     public Text ScoreText;
    10.  
    11.     // Use this for initialization
    12.     void Awake ()
    13.     {
    14.         ScoreText = GetComponent<Text> ();
    15.         Score = 0;
    16.     }
    17.  
    18.     // Adding Score points.
    19.     void Scoreadding ()
    20.     {
    21.         ScoreText.text = "Score: " + Score;
    22.     }
    23. }
    24.  
     
  15. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Are you certain your Scoreadding method is actually being executed?
    Time to add Debug.Log statements to the code, see whats going on.

    Code (csharp):
    1.  
    2. // if enemy is death...
    3.         void Death ()
    4.          {
    5.              Debug.Log("Debugging! EnemyHealth:Death.  Entry");
    6.             isDead = true;
    7.              Anim.SetTrigger ("Dead");
    8.              // Adding score points...
    9.             ScoreManager.Score = ScoreManager.Score + ScoreValue;
    10.             CapCollider.isTrigger = true;
    11.             EnemyAudio.clip = DeathClip;
    12.             EnemyAudio.Play();
    13.             Destroy (gameObject, 2f);
    14.              Debug.Log("Debugging! EnemyHealth:Death.  Exit");
    15.         }
    16.  
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEngine.UI;
    5. public class ScoreManager : MonoBehaviour
    6. {
    7.      public static int Score;
    8.     public Text ScoreText;
    9.      // Use this for initialization
    10.     void Awake ()
    11.     {
    12.         Debug.Log("Debugging! ScoreManager:Awake.  Entry");
    13.         ScoreText = GetComponent<Text> ();
    14.         Score = 0;
    15.     }
    16.     // Adding Score points.
    17.     void Scoreadding ()
    18.     {
    19.         Debug.Log("Debugging! ScoreManager:Scoreadding.  Entry");
    20.         ScoreText.text = "Score: " + Score;
    21.     }
    22. }
    23.  
    Confirm that you see
    Debugging: ScoreManager.Scoreadding. Entry
    in your console log


    And, of course, as always, confirm there are no other errors (build or execution) in your code in the console log
     
    Last edited: Jul 24, 2017
  16. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Try taking a look at post 611 and post 606.
     
  17. JoniBerg

    JoniBerg

    Joined:
    Jun 30, 2017
    Posts:
    14
    Yeah you are right man. Scoreadding. Entry don't execute. But no errors on build or execution.

    Code (CSharp):
    1. Debug.Log("Debugging: EnemyHealth.Death.  Entry");  // Console log is OK
    2. Debug.Log("Debugging: EnemyHealth.Death.  Exit"); // Console log is OK
    3. Debug.Log("Debugging: ScoreManager.Awake.  Entry"); // Console log is OK
    4. Debug.Log("Debugging: ScoreManager.Scoreadding.  Entry");  // Don't show in Console log
    5.  
     
  18. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    This is a time when it's ok to look at the "_Complete-Game" directory of the downloaded project.
    It's never a good idea to blindly copy things out of "_Complete-Game" directory, including prefabs or code. It may or may not work.
    But you can refer to it if you're unsure of things like project hierarchy, or a specific code snippet.

    If I open "..\Survival Shooter\Assets\_Complete-Game\Scripts\Managers\ScoreManager.cs" and look to
    the place where the score text is updated, I see:
    Code (csharp):
    1.  
    2.         void Update ()
    3.         {
    4.             // Set the displayed text to be the word "Score" followed by the score value.
    5.             text.text = "Score: " + score;
    6.         }
    7.  
    Note the method name is Update.

    So, If I were you, I would try changing your method name
    from:
    void Scoreadding ()
    to:
    void Update ()


    and, your variable name is Score while the one in the example is score.
     
  19. Darkaos

    Darkaos

    Joined:
    Nov 2, 2015
    Posts:
    2
    Im having a bit of a problem with the enemy spawn, at first I thought it was thanks to the NavMesh not reaching properly where the enemy spawns, then even after I moved the spawn point closer to the reach of the navmesh reach it still doesn't work properly.

    The enemy does spawn, but it doesn't interact with the player in any way, neither does it dish out damage nor does it receive damage; In unity I receive this error message in the console (NullReferenceException: Object reference not set to an instance of an object) and this error points towards the lines 27 of enemy movement and 65 of enemy attack, so the problem seems to be related to the player health.

    What should I do?
     
  20. Darkaos

    Darkaos

    Joined:
    Nov 2, 2015
    Posts:
    2
    Actually never mind, I noticed that the prefab used had the problem of being the same as in the "complete game" folder, wich was clashing with the prefab the tutorial teaches us to create, I substitued the prefab I wasusing with the one the game teaches us to create in our personal prefab folder and it stated working perfectly... someone should point this out in the next update of the PDF folder since it's not that easy to notice unless you come here.
     
  21. jacketgun

    jacketgun

    Joined:
    Jul 26, 2017
    Posts:
    4
    hi, im currently on chapter 2 and i just finished the coding part, but the player refuses to rotate.
    everything else works just fine, pls help.
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class PlayerMovement : MonoBehaviour
    5. {
    6.     public float speed = 6f;
    7.  
    8.     Vector3 movement;
    9.     Animator anim;
    10.     Rigidbody playerRigidbody;
    11.     int floorMask;
    12.     float camRayLength = 100f;
    13.  
    14.     private void Awake()
    15.     {
    16.         floorMask = LayerMask.GetMask("floor");
    17.         anim = GetComponent<Animator>();
    18.         playerRigidbody = GetComponent<Rigidbody>();
    19.     }
    20.  
    21.     private void FixedUpdate()
    22.     {
    23.         float h = Input.GetAxisRaw("Horizontal");
    24.         float v = Input.GetAxisRaw("Vertical");
    25.         Move(h, v);
    26.         Turning();
    27.         Animating(h, v);
    28.     }
    29.     private void Move(float h, float v)
    30.     {
    31.         movement.Set(h, 0f, v);
    32.  
    33.         movement = movement.normalized * speed * Time.deltaTime;
    34.  
    35.         playerRigidbody.MovePosition(transform.position + movement);
    36.     }
    37.     void Turning()
    38.     {
    39.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    40.  
    41.         RaycastHit FloorHit;
    42.  
    43.         if (Physics.Raycast(camRay, out FloorHit, camRayLength, floorMask))
    44.         {
    45.             Vector3 playerToMouse = FloorHit.point - transform.position;
    46.             playerToMouse.y = 0f;
    47.  
    48.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    49.             playerRigidbody.MoveRotation(newRotation);
    50.         }
    51.     }
    52.  
    53.  
    54.     void Animating(float h, float v)
    55.     {
    56.         bool walking = h != 0f || v != 0f;
    57.         anim.SetBool("IsWalking", walking);
    58.     }
    59. }
    60.  
     
  22. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    WRT to your line 16
    floorMask = LayerMask.GetMask("floor");
    In my case, the layermask was Floor with a capital F
    floorMask = LayerMask.GetMask("Floor");

    I don't know if that will make any difference at all

    Do you get any build/execution errors in the Console Log?
     
  23. jacketgun

    jacketgun

    Joined:
    Jul 26, 2017
    Posts:
    4

    ..... that was literally it lol
    good thing someone noticed!
     
  24. jacketgun

    jacketgun

    Joined:
    Jul 26, 2017
    Posts:
    4
    ok, so now i'm on chapter 9, and i have gotten the enemies to spawn and chase the player.
    but even though the zombears and hellephants have the same scripts and navmeshes i get these errors:

    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:76)
    PlayerShooting.Update () (at Assets/Scripts/Player/PlayerShooting.cs:37)

    ^ this happens when i shoot a zombear

    and

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

    ^ this happens when i reduce the health of a zombear to 0

    they still stop moving when this happens so im not sure how to fix it, as they should just stop trying to find the player when that happens..
     
  25. jacketgun

    jacketgun

    Joined:
    Jul 26, 2017
    Posts:
    4
    ok, so i managed to solve it by rearranging the order iof the components in the zombear gameobject....
    apparently that mattered...
     
  26. Deleted User

    Deleted User

    Guest

    THANK YOU SO MUCH this was really bothering the crap out of me, spent like 20 minutes just looking over the scripts trying to find what was wrong
     
  27. Deleted User

    Deleted User

    Guest

    I have completely finished the game build, but whenever I die the Game Over screen is only up for barely a second before it restarts the game. I tried changing the restart delay but this has no effect on the Game Over screen duration, just a quick pop up and then the game restarts. Anybody know what's going on?
     
  28. MedalHellWay

    MedalHellWay

    Joined:
    Jul 28, 2013
    Posts:
    154
    Hi!
    I noticed that if the "Player" is not tagged in the Unity editor, the string returns an error.
    Then, if I tag the player and I write the "old" string:
    Code (CSharp):
    1. player = GameObject.FindGameObjectWithTag("Player").transform;
    the code work well (I use the new Unity 2017.1b).
     
  29. TitansValleyEnt

    TitansValleyEnt

    Joined:
    Aug 8, 2017
    Posts:
    3
    Please I need to know this too! I added a new enemy and everything works but this StartSinking function. I can not find where it is called!!! PLEASE HELP! :D

    SOLVED! :D I finally found there is an event tab buried in the inspector view on an animation. You can use that event tab to create function calls and other things tied to the animation!

    Thanks!
     
    Last edited: Aug 8, 2017
  30. TitansValleyEnt

    TitansValleyEnt

    Joined:
    Aug 8, 2017
    Posts:
    3

    That's the only other thing that I cant figure out either myself.
     
  31. TitansValleyEnt

    TitansValleyEnt

    Joined:
    Aug 8, 2017
    Posts:
    3
    Not much to go on based on the screen shot but maybe you didn't add the actual Hellephant to the enemy manager that is trying to spawn him? I'm guess basically when the game goes to spawn something at 10 seconds it has nothing there. Should just bring up the enemy manager and drag in Hellephant like the other two.
     
  32. frictionmitch

    frictionmitch

    Joined:
    Mar 4, 2017
    Posts:
    3
    For some reason, I'm getting an error with the Hellephant and Zombear in the game. I keep getting this error:

    "
    NullReferenceException: Object reference not set to an instance of an object
    CompleteProject.EnemyAttack.Update () (at Assets/_Complete-Game/Scripts/Enemy/EnemyAttack.cs:65)"

    All of my game objects seem to be linked properly. I see both enemies spawn but they don't move. Only the zombunny seems to be moving properly

    Figured it out...For some reason both prefabs were linked to scripts from "Completed" folder. I deleted the components and added the correct scripts...now works
     
    Last edited: Aug 10, 2017
  33. frictionmitch

    frictionmitch

    Joined:
    Mar 4, 2017
    Posts:
    3
    "Index out of range..." is referring to the Array of spawn points. The spawn location isn't set or you changed the number of the Element from 0. 0 is the first item which should be the HellephantSpawnLocation. If you changed that "0" to any other number, it will be looking for a location that doesn't exist.
     
  34. hanghanghappy

    hanghanghappy

    Joined:
    Aug 10, 2017
    Posts:
    4
    I have got script error while working on part 6 of 10 !
    I follow every step of the tutorial but it shows this message after injecting the EnemyAttack script

    Assets/Scripts/Enemy/EnemyAttack.cs(5,14): error CS0101: The namespace `global::' already contains a definition for `EnemyAttack'

    What happens ? Can someone please help me to solve this ?

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class EnemyAttack : MonoBehaviour
    5. {
    6.     public float timeBetweenAttacks = 0.5f;
    7.     public int attackDamage = 10;
    8.  
    9.  
    10.     Animator anim;
    11.     GameObject player;
    12.     PlayerHealth playerHealth;
    13.     //EnemyHealth enemyHealth;
    14.     bool playerInRange;
    15.     float timer;
    16.  
    17.  
    18.     void Awake ()
    19.     {
    20.         player = GameObject.FindGameObjectWithTag ("Player");
    21.         playerHealth = player.GetComponent <PlayerHealth> ();
    22.         //enemyHealth = GetComponent<EnemyHealth>();
    23.         anim = GetComponent <Animator> ();
    24.     }
    25.  
    26.  
    27.     void OnTriggerEnter (Collider other)
    28.     {
    29.         if(other.gameObject == player)
    30.         {
    31.             playerInRange = true;
    32.         }
    33.     }
    34.  
    35.  
    36.     void OnTriggerExit (Collider other)
    37.     {
    38.         if(other.gameObject == player)
    39.         {
    40.             playerInRange = false;
    41.         }
    42.     }
    43.  
    44.  
    45.     void Update ()
    46.     {
    47.         timer += Time.deltaTime;
    48.  
    49.         if(timer >= timeBetweenAttacks && playerInRange/* && enemyHealth.currentHealth > 0*/)
    50.         {
    51.             Attack ();
    52.         }
    53.  
    54.         if(playerHealth.currentHealth <= 0)
    55.         {
    56.             anim.SetTrigger ("PlayerDead");
    57.         }
    58.     }
    59.  
    60.  
    61.     void Attack ()
    62.     {
    63.         timer = 0f;
    64.  
    65.         if(playerHealth.currentHealth > 0)
    66.         {
    67.             playerHealth.TakeDamage (attackDamage);
    68.         }
    69.     }
    70. }
    71.  
     
  35. JacekMackiewicz

    JacekMackiewicz

    Unity Technologies

    Joined:
    Jul 5, 2017
    Posts:
    34
    Hi Hanghanghappy,

    The error message means that somewhere else in your project folder there already is a class named "EnemyAttack". When you create and name a new script within Unity, it adds the line

    "public class EnemyAttack : MonoBehaviour"

    at the top of your script. This name needs to be unique otherwise the script won't work and Unity will give you the CS0101 error. I'm guessing somewhere in your project files there is a completed "EnemyAttack" script from the tutorial. To fix this either delete that finished script, or rename your new script something else. (Remember that if you rename it in the Unity Editor it won't automatically rename it within that first MonoBehaviour line and that those two names have to match)
     
  36. DemiHansen

    DemiHansen

    Joined:
    Aug 24, 2017
    Posts:
    1
    I am using to most recent version of unity for 2017 and the canvas group in the add component section under miscellaneous is not there what do I do
     
  37. duxck

    duxck

    Joined:
    Dec 7, 2015
    Posts:
    3
    Thanks for the information! Was scratching my head with that =)
    In case someone else is looking for this solution.

    When you're in the animator, clicking the arrow between Idle and Move animation the box "Has Exit Time" should be unchecked and under "Settings" you can make sure "Exit Time" is either 0 or grayed out. Make sure you do it to both arrows.
     

    Attached Files:

  38. duxck

    duxck

    Joined:
    Dec 7, 2015
    Posts:
    3
    I am having the same issue as @Douglas1701 In Chapter 3 I've followed the instructions and can't find where the issue is.

    Previous posters have said that the issue might be Camera settings or that the Start function isn't run.
    My CameraFollow.cs looks like this

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraFollow : MonoBehaviour {
    6.  
    7.     public Transform target;
    8.     public float smoothing = 5f;
    9.  
    10.     private Vector3 offset;
    11.  
    12.     private void Start()
    13.     {
    14.         offset = transform.position - target.position;
    15.  
    16.         Debug.Log("Offset: " + offset.ToString());
    17.         /**
    18.         * Outputs:
    19.         * Offset: (1.0, 15.0, -22.0)
    20.         * UnityEngine.Debug:Log(Object)
    21.         * CameraFollow: Start()(at Assets / Scripts / Camera / CameraFollow.cs:15)
    22.         **/
    23.     }
    24.  
    25.     private void FixedUpdate()
    26.     {
    27.         Vector3 targetCamPos = target.position + offset;
    28.  
    29.         // Spams console with the same message since camera isn't moving.
    30.         Debug.Log("targetCamPos: " + offset.ToString());
    31.         /** Outputs:
    32.          * targetCamPos: (1.0, 15.0, -22.0)
    33.          * UnityEngine.Debug:Log(Object)
    34.          * CameraFollow:FixedUpdate() (at Assets/Scripts/Camera/CameraFollow.cs:22)
    35.          **/
    36.         transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing) * Time.deltaTime;
    37.  
    38.         // Spams console with the same message since camera isn't moving.
    39.         Debug.Log("New transform.position: " + transform.position.ToString());
    40.         /** Outputs:
    41.          * New transform.position: (0.0, 0.3, -0.4)
    42.          * UnityEngine.Debug:Log(Object)
    43.          * CameraFollow:FixedUpdate() (at Assets/Scripts/Camera/CameraFollow.cs:25)
    44.          **/
    45.     }
    46. }
    47.  
    My Main Camera Inspector looks like the on in the tutorial as far as I can see.


    When I try to run the game half the screen is gray, with a black line between the gray and the player area. I can move the character but the camera doesn't follow it. If I move too close to the camera my model looks like the camera is inside it (invisible).



    The gray part is because of my "Clear Flags" is set to skybox, same issue but bottom half is all black if I change it to solid color.

    It would seem that the reason for this is that the camera isn't connected to the player gameobject. I can't find why that is though.
     
  39. duxck

    duxck

    Joined:
    Dec 7, 2015
    Posts:
    3

    Well oh my sweet baby jesus.

    Found the issue.

    Change from:
    transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);

    To:
    transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);

    Space between "...Lerp" and "(transform..." had to go.
     
  40. richardhowell879

    richardhowell879

    Joined:
    Aug 25, 2017
    Posts:
    1
    Ugh. No errors, and everything in my editor seems in order. None of my spawn points are functioning at all. No spawning.
     
  41. crazy8z

    crazy8z

    Joined:
    Sep 6, 2017
    Posts:
    1
    Hello all, I am having a couple of issues with my version of this tutorial. For starters I followed thru the tutorial twice over and I am having two main issues. The first one is that besides the zombunnies, my enemies will spawn and stay idle at their spawn point. I am not able to interact with them thru regular shooting and when I walk to them they do not attack me. The other issue, which I believe is probably related is that I get an error code that brings me to EnemyManager and tells me that the
     
  42. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144

    take a look at posts: 676, 670, 669, 633, and 606
    see if they help
     
  43. ladyyujing

    ladyyujing

    Joined:
    Sep 10, 2017
    Posts:
    2
    In prefabs I drag Environment to Hierarchy. Scene shows nothing.
     

    Attached Files:

  44. jessica_boddicker

    jessica_boddicker

    Joined:
    Sep 3, 2017
    Posts:
    1
    I believe this problem can be solved by navigating to Models -> characters and then drag/drop ZomBear into the hierarchy. A prefab can then be made from the edited ZomBear... If there is a better way to do this, I'm all ears! i've been struggling with this too :)
     
  45. marcc2003

    marcc2003

    Joined:
    Sep 14, 2017
    Posts:
    2
    Problem with Death animation and score: The StartSinking function is called twice after an enemy is killed, so the score is added twice (the Death() function is only called once). According to the Upgrade Manual, "Has Exit Time" should be unchecked, but when I do this in EnemyAC for the transition AnyState->Death, the animation is not played correctly and the StartSinking is called even more often (8 times)! As a workaround, I put the line "ScoreManager.score += scoreValue;" into the Death()-function, but I would be interested in the cause of the problem...
     
  46. Kozki

    Kozki

    Joined:
    Aug 28, 2017
    Posts:
    1
    Hello all !

    Tutorial done on my side, still need to check the Audio upgrade parts.
    I'm also trying to add some tweaks and new enemies:

    - I've mixed spawning points so that enemies can come from all sides and not only from one spawning points.
    - I've created new enemies:
    a. Green Zombunny (ZombGreeny) : Faster, weaker, but deadlier
    b. Orange Hellephant (Deathlephant): More HP, More Damage, More Points
    c. Red Zombbear (ZombHeart): More HP, Less Damage, Give back health point to the player when shot down.

    --> I'm having trouble on the last part: I don't manage to give the player 10 HP back when he kills a ZombHeart.

    My first guess was to add a line in the EnemyHealth Script in the StartSinking function just after the following line:

    ScoreManager.score += scoreValue;

    PlayerHealth.currentHealth = currentHealth + 10;

    I call the PlayerHealth reference at the top of the script, thus I need to drag and drop the player GameObject onto the inspector to link it.

    However, it doesn't work, enemy get killed but no HP is added back to the player.

    Any clue how I could do that ?

    Thanks
     
  47. marcc2003

    marcc2003

    Joined:
    Sep 14, 2017
    Posts:
    2
    The enemies are prefabs (as you want to instantiate them at runtime). What you need is a reference to an instance of the PlayerHealth-class (which is a component of the Player GameObject). You cannot do this with prefabs. In fact, it should not be possible to drag and drop this. Did you do the drag and drop with an instance of the prefab? It simply does not make sense for a prefab (that could be used in any scene of your game) to hold a reference to a certain instance of a class in a certain scene. You will have to create the reference at runtime. The same thing is done in EnemyAttack:
    player = GameObject.FindGameObjectWithTag ("Player");
    playerHealth = player.GetComponent <PlayerHealth> ();

    Look up the Space Shooter Tutorial vid 3.2 (Counting points) from 10:10 on, the problem is explained there in more detail (and a possible solution).

    Btw: Another possibility would be to use the Attack function in EnemyAttack and inflict a negative damage. A reference to that can be created with a simple GetComponent in EnemyHealth (as it is a component of the same prefab). To set the negative damage, you could set the class variable attackDamage to the corresponding negative value. More elegant might be to give the attack function an argument for the inflicted (possibly negative) damage (you can even do this by function overloading if you know what that is).
     
  48. csjacsj

    csjacsj

    Joined:
    Sep 19, 2017
    Posts:
    1
    yeah I also ran into this problem, then I fixed it. you should check that in unity top right corner, select 'Layers' and make sure you got those layers display or not set right, that should be the solution.
     
    Last edited: Sep 20, 2017
  49. ToxicSeaSponge

    ToxicSeaSponge

    Joined:
    Sep 25, 2017
    Posts:
    6
    hey guys,

    can anyone tell me why microsfot visual studio won't accept "animating" even though it will accept "turning"?

    thanks

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.  
    6.     public float speed = 6f;
    7.  
    8.     Vector3 movement;
    9.     Animator anim;
    10.     Rigidbody playerRigidbody;
    11.     int floorMask;
    12.     float camRayLength = 100f;
    13.  
    14.    void Awake()
    15.     {
    16.         floorMask = LayerMask.GetMask("floor");
    17.         anim = GetComponent<Animator>();
    18.         playerRigidbody = GetComponent<Rigidbody>();
    19.  
    20.     }
    21.  
    22.     private void FixedUpdate()
    23.     {
    24.         float h = Input.GetAxisRaw("Horizontal");
    25.         float v = Input.GetAxisRaw("Vertical");
    26.  
    27.         Move(h, v);
    28.         Turning();
    29.        Animating(h, v);
    30.     }
    31.  
    32.     private void Move (float h, float v)
    33.     {
    34.         movement.Set(h, 0f, v);
    35.         movement = movement.normalized * speed * Time.deltaTime;
    36.         playerRigidbody.MovePosition(transform.position + movement);
    37.     }
    38.  
    39.     void Turning ()
    40.     {
    41.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    42.         RaycastHit floorHit;
    43.  
    44.         if(Physics.Raycast  (camRay, out floorHit, camRayLength,floorMask))
    45.         {
    46.             Vector3 playerToMouse = floorHit.point - transform.position;
    47.             playerToMouse.y = 0f;
    48.  
    49.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    50.             playerRigidbody.MoveRotation(newRotation);
    51.         }
    52.  
    53.         void Animating (float h,float v)
    54.         {
    55.             bool walking = h != 0f || v != 0f;
    56.             anim.SetBool("IsWalking", walking);
    57.         }
    58.     }
    59. }
    60.  
     
  50. Paintbrush11

    Paintbrush11

    Joined:
    Sep 11, 2017
    Posts:
    3
    A lot of people seem to have a problem where the bullet goes right through the enemies and don't seem to harm them. Took me a good hour, but I figured it out!
    Where the guy in the tutorial says to make the zombunny and its children shootable, he's not talking about tags. He's talking about the Layer drop-down next to it. After setting its layer to Shootable, it works just fine for me.
    Hope this helped someone!