Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Survival Shooter Q&A

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

  1. drandy007

    drandy007

    Joined:
    Mar 11, 2018
    Posts:
    8
  2. lstewart

    lstewart

    Joined:
    May 2, 2018
    Posts:
    1
    In the first video, instructions say to choose Floor layer for the Floor object, but there is no Floor layer in the list.
     
  3. Lauraunkut

    Lauraunkut

    Joined:
    Oct 12, 2018
    Posts:
    6
    Hi everyone, I try to apply the ScoreManager Script to an other project, but it doesn't work... My project is a killing zombie game, when a zombie die, the Score of the player is supposed to increase, but it is not the case...
    There are my two scripts, can you help me please.

    One for my ennemi

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ZombieEnergyController : MonoBehaviour {
    6.  
    7.     private int myZombieEnergy;
    8.     TextMesh myText;
    9.     public int scoreValue = 10;
    10.     private ScoreManager gameController;
    11.  
    12.    
    13.     // Use this for initialization
    14.     void Start()
    15.     {
    16.         myText = GetComponent<TextMesh>();
    17.         myZombieEnergy = 99;
    18.        
    19.     }
    20.  
    21.     void Update()
    22.     {
    23.         myText.text = " " + myZombieEnergy + "%";
    24.     }
    25.  
    26.     public void LooseHealth(int h)
    27.     {
    28.         myZombieEnergy -= h*2;
    29.     }
    30.  
    31.     public bool IsZombieDead()
    32.     {
    33.         if (myZombieEnergy <= 0)
    34.          return true;
    35.        
    36.        
    37.         else
    38.             return false;
    39.        
    40.     }
    41.     public void Zombiemort()
    42.     {
    43.         if (myZombieEnergy <= 0)
    44.         {
    45.            
    46.         ScoreManager.score += scoreValue;
    47.         }
    48.        
    49.  
    50.     }
    51.  
    52. }
    53.  
    And this one for the ScoreText:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class ScoreManager : MonoBehaviour
    6. {
    7.     public static int score;
    8.    
    9.  
    10.     Text text;                    
    11.  
    12.  
    13.     void Awake()
    14.     {
    15.         // On va chercher le componenrt Text
    16.         text = GetComponent<Text>();
    17.  
    18.         // Remet le score à zéro.
    19.          score = 0;
    20.        
    21.     }
    22.  
    23.  
    24.     void Update()
    25.     {
    26.         // On affiche le texte score suivie de la valeur du score
    27.          text.text = "Score: " + score;
    28.        
    29.     }
    30. }
    Thank you very much
     
  4. alver1998

    alver1998

    Joined:
    Oct 14, 2018
    Posts:
    1
    Problem of animation solved. The line Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition); references the main camera. The problem is that the main camera tag "Untagged" default. You have to change the tag to "MainCamera".
     
    ScorpionVII likes this.
  5. insj1519_unity

    insj1519_unity

    Joined:
    Nov 10, 2018
    Posts:
    1
    i'm Unity Beginner who is studying while watching your tutorial. During the study, there are two things('entry' & 'anystate') in the animator controller window: 'entry' and 'Anystate'. Is there any way to get rid of the 'entry' ??? Your video will only show 'anystate' and no entry will appear.


    And does that cause the problem that my player just slides and moves on the 'transform.position' as freeze body and does not move like shaking?
     
  6. CTata

    CTata

    Joined:
    Nov 10, 2018
    Posts:
    1
    Thank you! I just spent two hours going over forums and reviewing my code against sample. Ended up doing a cut/paste of the revised code on the tutorial page and kept getting that damn error. Now it works, so again, Thank You!
     
  7. taleslfm

    taleslfm

    Joined:
    Nov 23, 2018
    Posts:
    1
    I was doing a class on doing a game just like this but I couldn't use the package to publish the final game.
    So i was searching for a package to replace it and came across this one.
    My question is, can I do it with this package? My scripts just using the graphics?

    Thanks in advance.
     
  8. adhochero

    adhochero

    Joined:
    Feb 2, 2017
    Posts:
    38
    I have a question. what are the use rights on these assets?
     
  9. grimsleysebastian2024

    grimsleysebastian2024

    Joined:
    Nov 29, 2018
    Posts:
    1
    Somehow the zombunny won't move despite the fact that i followed the tutorial word for word. I am legitimately stuck on creating enemy #1
     
  10. LucasSchott

    LucasSchott

    Joined:
    Dec 30, 2017
    Posts:
    2
    Does anyone know how to fix the Zombunny not dying when I shoot it and giving this error message whenever I shoot it? I didn't change any of the code and did everything in the editor exactly how it said so I can't figure out what I am doing wrong.

    The error message:
    NullReferenceException: Object reference not set to an instance of an object
    EnemyHealth.TakeDamage (Int32 amount, Vector3 hitPoint) (at Assets/Included With Tutorial/Scripts/Enemy/EnemyHealth.cs:50)
    PlayerShooting.Shoot () (at Assets/Included With Tutorial/Scripts/Player/PlayerShooting.cs:76)
    PlayerShooting.Update () (at Assets/Included With Tutorial/Scripts/Player/PlayerShooting.cs:37)

    The files it lists:

    Code (CSharp):
    1. using UnityEngine;  //this one is EnemyHealth.cs
    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.     }
    29.  
    30.  
    31.     void Update ()
    32.     {
    33.         if(isSinking)
    34.         {
    35.             transform.Translate (-Vector3.up * sinkSpeed * Time.deltaTime);
    36.         }
    37.     }
    38.  
    39.  
    40.     public void TakeDamage (int amount, Vector3 hitPoint)
    41.     {
    42.         if(isDead)
    43.             return;
    44.      
    45.  
    46.         enemyAudio.Play ();
    47.  
    48.         currentHealth -= amount;
    49.      
    50.         hitParticles.transform.position = hitPoint; // this is the line it seems to get stuck on
    51.      
    52.         hitParticles.Play();
    53.      
    54.         if(this.currentHealth <= 0)
    55.         {
    56.             this.Death ();
    57.          
    58.         }
    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.         Debug.Log("dead");
    73.     }
    74.  
    75.  
    76.     public void StartSinking ()
    77.     {
    78.         GetComponent <UnityEngine.AI.NavMeshAgent> ().enabled = false;
    79.         GetComponent <Rigidbody> ().isKinematic = true;
    80.         isSinking = true;
    81.         //ScoreManager.score += scoreValue;
    82.         Destroy (gameObject, 2f);
    83.     }
    84. }
    85.  
    Code (CSharp):
    1. using UnityEngine; //this one is PlayerShooting.cs
    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.                 enemyHealth.TakeDamage (damagePerShot, shootHit.point);
    77.             }
    78.             gunLine.SetPosition (1, shootHit.point);
    79.         }
    80.         else
    81.         {
    82.             gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
    83.         }
    84.     }
    85. }
    86.  
     
  11. adhochero

    adhochero

    Joined:
    Feb 2, 2017
    Posts:
    38
    Has anyone run into an issue after around part 8 where the enemies go into idle a couple seconds after starting the game and also no long follow the payer even before they go to idle?

    It worked fine before prefabing them, when the bunny was just in the scene it followed and would attack. You can still shoot them. But they just stop. Any ideas on what could have gone wrong in parts 8-10?
     
  12. DottMySaviour

    DottMySaviour

    Joined:
    Nov 17, 2018
    Posts:
    3
    I have the same issue with this guy, I made a post here about it. Someone please let me understand what's going on.
     
  13. ScorpionVII

    ScorpionVII

    Joined:
    Oct 31, 2018
    Posts:
    3
    Thank you for this. It has been upsetting and confusing me for far to long. :)
     
  14. ScorpionVII

    ScorpionVII

    Joined:
    Oct 31, 2018
    Posts:
    3
    This is how it is.
     
  15. Triad946

    Triad946

    Joined:
    Dec 13, 2018
    Posts:
    6
    I'm going through the Survival shooter tutorial, but I've come across a few problems: The player character won't look to the cursor and will only turn in the corners, and the only enemy I have in at the moment is stuck in place.

    I've edited the code, match what's here, but it still doesn't work.
    Code samples:

    EnemyMovement
    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.     UnityEngine.AI.NavMeshAgent nav;
    10.  
    11.  
    12.     void Awake ()
    13.     {
    14.         player = GameObject.Find("Player").transform;
    15.         playerHealth = player.GetComponent <PlayerHealth> ();
    16.         enemyHealth = GetComponent <EnemyHealth> ();
    17.         nav = GetComponent <UnityEngine.AI.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. }
    33.  
    PlayerMovement
    Code (Csharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;            // The speed that the player will move at.
    6.  
    7.     Vector3 movement;                   // The vector to store the direction of the player's movement.
    8.     Animator anim;                      // Reference to the animator component.
    9.     Rigidbody playerRigidbody;          // Reference to the player's rigidbody.
    10.     int floorMask;                      // A layer mask so that a ray can be cast just at gameobjects on the floor layer.
    11.     float camRayLength = 100f;          // The length of the ray from the camera into the scene.
    12.  
    13.     void Awake()
    14.     {
    15.         // Create a layer mask for the floor layer.
    16.         floorMask = LayerMask.GetMask("Floor");
    17.  
    18.         // Set up references.
    19.         anim = GetComponent<Animator>();
    20.         playerRigidbody = GetComponent<Rigidbody>();
    21.     }
    22.  
    23.     void FixedUpdate()
    24.     {
    25.         // Store the input axes.
    26.         float h = Input.GetAxisRaw("Horizontal");
    27.         float v = Input.GetAxisRaw("Vertical");
    28.  
    29.         // Move the player around the scene.
    30.         Move(h, v);
    31.  
    32.         // Turn the player to face the mouse cursor.
    33.         Turning();
    34.  
    35.         // Animate the player.
    36.         Animating(h, v);
    37.     }
    38.  
    39.     void Move(float h, float v)
    40.     {
    41.         // Set the movement vector based on the axis input.
    42.         movement.Set(h, 0f, v);
    43.  
    44.         // Normalise the movement vector and make it proportional to the speed per second.
    45.         movement = movement.normalized * speed * Time.deltaTime;
    46.  
    47.         // Move the player to it's current position plus the movement.
    48.         playerRigidbody.MovePosition(transform.position + movement);
    49.     }
    50.  
    51.     void Turning()
    52.     {
    53.         // Create a ray from the mouse cursor on screen in the direction of the camera.
    54.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    55.         Debug.Log("camRay " + camRay);
    56.         // Create a RaycastHit variable to store information about what was hit by the ray.
    57.         RaycastHit floorHit;
    58.  
    59.         // Perform the raycast and if it hits something on the floor layer...
    60.         if (Physics.Raycast(camRay, out floorHit, camRayLength, floorMask))
    61.         {
    62.             // Create a vector from the player to the point on the floor the raycast from the mouse hit.
    63.             Vector3 playerToMouse = floorHit.point - transform.position;
    64.  
    65.             // Ensure the vector is entirely along the floor plane.
    66.             playerToMouse.y = 0f;
    67.             Debug.Log("playerToMouse " + playerToMouse);
    68.             // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
    69.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    70.             Debug.Log("newRotation " + newRotation);
    71.             // Set the player's rotation to this new rotation.
    72.             playerRigidbody.MoveRotation(newRotation);
    73.             Debug.Log("playerRigidbody " + playerRigidbody);
    74.         }
    75.         else
    76.         Debug.Log("ray didnt hit");
    77.     }
    78.  
    79.     void Animating(float h, float v)
    80.     {
    81.         // Create a boolean that is true if either of the input axes is non-zero.
    82.         bool walking = h != 0f || v != 0f;
    83.  
    84.         // Tell the animator whether or not the player is walking.
    85.         anim.SetBool("IsWalking", walking);
    86.     }
    87. }
    88.  
    What should I do when the debug says "ray didn't hit?"
    Any help would be great![/code]
     
    Last edited: Dec 17, 2018
  16. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,928
    I really wanted to help, but your code is not readable. Please go back, edit it (link at the bottom of your post), and put your code into code tags (button for it is in the toolbar when you're editing your post).
     
  17. Triad946

    Triad946

    Joined:
    Dec 13, 2018
    Posts:
    6
    Done
     
  18. Triad946

    Triad946

    Joined:
    Dec 13, 2018
    Posts:
    6
    Actually, I think I know why the Survival shooter isn't working the way it should: I put it on a flash drive, and that messed it up somehow.
     
  19. Sethidos34

    Sethidos34

    Joined:
    Dec 17, 2018
    Posts:
    1
    Hey Guys, total novice here
    I'm trying to get through Section 4 'creating enemy one' part of the tutorial and i'm at the part where you need to bake the AI navigation.
    but my options don't match those in the video. There is no 'Width Accuracy %' slider on mine. I just have a manual Voxal option and i don't know what any of it means. please help.
     
  20. nopharbm

    nopharbm

    Joined:
    Dec 29, 2018
    Posts:
    3
    Hi,
    This is my first time using unity. Am really new to all of this.
    I opened the tutorial for the survival shooter, and the scenes folder is not there. There is a list of folders under assets, just not scenes.
    Why is that? Where can I find it?
     
  21. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    Did you start using the videos? I'm pretty sure the first one will teach you how to create a new scene, install the first prefabs and so on. ;)
     
  22. nopharbm

    nopharbm

    Joined:
    Dec 29, 2018
    Posts:
    3
    Hi,
    The videos are how I noticed the scene folder isn't there. It opened up as a clean slate, and I didn't open the complete project. The scenes folder just isn't anywhere to be found. One of the issues I can think of is that I have unity 2018 while they're showing on an earlier version.
     
    Last edited: Dec 29, 2018
  23. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    Where did you download the project? The first thing you should do is get rid of the "complete" folder.

    The scene you saved went exactly where you put it; if the "Scenes" folder does not exist you must create it in the Assets directory. :)

    If this is the very first time you use Unity, it would be better that you start with the Roll a Ball tutorial; it will teach you the basics you'll need to make further projects.
     
  24. nopharbm

    nopharbm

    Joined:
    Dec 29, 2018
    Posts:
    3
    Thank you :)
     
  25. gcsexton

    gcsexton

    Joined:
    Sep 5, 2017
    Posts:
    1
    UPDATE: SOLVED

    For anyone using a newer version of Unity there is a new Input Manager. I was trying avoid looking at the Completed Game code, but that's when I realized they included a new tag for controls

    NOTE - You need add "using UnitySampleAssets.CrossPlatformInput;" at the top.


    Code (CSharp):
    1. void FixedUpdate ()
    2.         {
    3.             // Store the input axes.
    4.             float h = CrossPlatformInputManager.GetAxisRaw("Horizontal");
    5.             float v = CrossPlatformInputManager.GetAxisRaw("Vertical");
    6.  
    7.             // Move the player around the scene.
    8.             Move (h, v);
    9.  
    10.             // Turn the player to face the mouse cursor.
    11.             Turning ();
    12.  
    13.             // Animate the player.
    14.             Animating (h, v);
    15.         }
    Hi everyone - I'm having trouble getting through the second section of the tutorial. I'm using Unity 2018 and I've copied the code as best as possible but for some reason the character doesn't move around at all when using the A, S, W, D keys. I'm not getting any errors though and the console is coming up clean. Thoughts?

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5.  
    6. public class PlayerMovement : MonoBehaviour
    7. {
    8.     public float speed = 6f;
    9.  
    10.     Vector3 movement;
    11.     Animator anim;
    12.     Rigidbody playerRigidbody;
    13.     int floorMask;
    14.     float camRayLength = 100f;
    15.  
    16.     void awake(){
    17.         // Create a layer mask for the floor layer.
    18.         floorMask = LayerMask.GetMask("Floor");
    19.  
    20.         // Set up references.
    21.         anim = GetComponent<Animator> ();
    22.         playerRigidbody = GetComponent<Rigidbody> ();
    23.     }
    24.  
    25.     void fixedUpdate(){
    26.         // Store the input axes.
    27.         float h = Input.GetAxisRaw ("Horizontal");
    28.         float v = Input.GetAxisRaw ("Vertical");
    29.  
    30.         Move (h, v);
    31.         Turning ();
    32.         Animating (h, v);
    33.     }
    34.  
    35.     void Move (float h, float v){
    36.         // Set the movement vector based on the axis input.
    37.         movement.Set(h, 0f, v);
    38.  
    39.         // Normalise the movement vector and make it proportional to the speed per second.
    40.         movement = movement.normalized * speed * Time.deltaTime;
    41.  
    42.         // Move the player to it's current position plus the movement.
    43.         playerRigidbody.MovePosition (transform.position + movement);
    44.  
    45.     }
    46.  
    47.     void Turning (){
    48.         // Create a ray from the mouse cursor on screen in the direction of the camera.
    49.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    50.         Debug.Log("camRay " + camRay);
    51.         // Create a RaycastHit variable to store information about what was hit by the ray.
    52.         RaycastHit floorHit;
    53.  
    54.         // Perform the raycast and if it hits something on the floor layer...
    55.         if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask)){
    56.  
    57.             // Create a vector from the player to the point on the floor the raycast from the mouse hit.
    58.             Vector3 playerToMouse = floorHit.point - transform.position;
    59.  
    60.             // Ensure the vector is entirely along the floor plane.
    61.             playerToMouse.y = 0f;
    62.             Debug.Log("playerToMouse " + playerToMouse);
    63.             // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
    64.             Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
    65.             Debug.Log("newRotation " + newRotation);
    66.             // Set the player's rotation to this new rotation.
    67.             playerRigidbody.MoveRotation (newRotation);
    68.             Debug.Log("playerRigidbody " + playerRigidbody);
    69.         }
    70.         else
    71.         Debug.Log("Ray didn't hit...");
    72.  
    73.     }
    74.  
    75.     void Animating (float h, float v){
    76.  
    77.         // Create a boolean that is true if either of the input axes is non-zero.
    78.         bool walking = h!=0f || v!=0f;
    79.  
    80.         // Tell the animator whether or not the player is walking.
    81.         anim.SetBool("IsWalking", walking);
    82.  
    83.     }
    84.  
    85. }
    86.  
    A few other notes from rummaging through the forum:
    1. I tried taking out the floorMask from the If statement and didn't yield any results.
    2. I tagged Main Camera as MainCamera and that didn't do anything either
    There is clearly something happening as the game runs, but the player doesn't respond/move/trigger animation pressing any of the movement keys. I feel like the problem has something to do with the Move function, but for Unity 2018.2.18f1 I'd think this would be something non-issue.
     
    Last edited: Jan 7, 2019
  26. ANONTRICYBER99

    ANONTRICYBER99

    Joined:
    Jan 16, 2019
    Posts:
    1
     
  27. Naiskick

    Naiskick

    Joined:
    Oct 14, 2018
    Posts:
    12
    You help me solve the problem, thank you !
     
  28. ChenBrendon

    ChenBrendon

    Joined:
    Feb 26, 2019
    Posts:
    2
    Hello, I'm having trouble on part 2 with the movement script.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class PlayerMovement : MonoBehaviour
    4. {
    5.     public float speed = 6f;
    6.  
    7.     Vector3 movement;
    8.     Animator anim;
    9.     Rigidbody playerRigidbody;
    10.     int floorMask;
    11.     float camRayLength = 100f;
    12.  
    13.     void Awake()
    14.     {
    15.         floorMask = LayerMask.GetMask("Floor");
    16.         anim = GetComponent<Animator>();
    17.         playerRigidbody = GetComponent<Rigidbody>();
    18.     }
    19.  
    20.     private void FixedUpdate()
    21.     {
    22.         float h = Input.GetAxisRaw("Horizontal");
    23.         float v = Input.GetAxisRaw("Vertical");
    24.  
    25.         Move(h, v);
    26.         Turning();
    27.         Animating(h, v);
    28.     }
    29.  
    30.     void Move(float h, float v)
    31.     {
    32.         movement.Set(h, 0f, v);
    33.         movement = movement.normalized * speed * Time.deltaTime;
    34.         playerRigidbody.MovePosition(transform.position + movement);
    35.     }
    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.  
    50.             playerRigidbody.MovePosition(newRotation);
    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.  
    I get this error, and I'm not sure why :
    Assets/Scripts/Player/PlayerMovement.cs(50,42): error CS1503: Argument 1: cannot convert from 'UnityEngine.Quaternion' to 'UnityEngine.Vector3'

    Thanks for the help :)
     
  29. ChenBrendon

    ChenBrendon

    Joined:
    Feb 26, 2019
    Posts:
    2
    Woops!

    Found what was wrong, after copy and pasting the script from the video lesson I had found it to be working. After reviewing my code:
    At line 50 it should say
    playerRigidbody.MoveRotation(newRotation);
    NOT
    playerRigidbody.MovePosition(newRotation);
     
  30. unity_N44Hx3y7Delvig

    unity_N44Hx3y7Delvig

    Joined:
    Dec 30, 2018
    Posts:
    1
    My player moves faster horizontal. I am unsure what the problem is. Vertical he moves fine.
     
  31. mishelbi

    mishelbi

    Joined:
    Jan 20, 2019
    Posts:
    8
    mine.PNG video.PNG

    Left is my screen and right is a screen shot of video.

    I'm on 07. Hurting Enemies. My inspector screen for the line renderer looks different than on the video. The video shows going into the parameters and setting Start Width and End Width fields. My inspector does not have a parameter section. It has a size field and under it index x y z with 0 1 under it like a grid. How do I adjust the size on
    this screen or is it even necessary any longer?
     
  32. ApocFI

    ApocFI

    Joined:
    May 26, 2017
    Posts:
    33
    I believe you can type the width value next to the red line in the graph. So I believe you should change the width from 1.0 to .05 (or whatever you area happy with).
     
  33. UnboundGodz

    UnboundGodz

    Joined:
    Nov 15, 2017
    Posts:
    2
    Really wish while loading the Environment in Hierachy didnt cause my system to lock up and freeze during or after completing the baking process. Have to disable "Lighting - Auto Generate" to not have to go through that, but at this point, whats the point of it then!?! Mind you I have a Ryzen 7 1700x at 3.9GHz, 16GB RAM 2400MHz C16, and a RX 580 8GB so you would assume decent enough to load a minimal template. ;(
     
  34. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    You don't need to bake the lights in this project. Just modify the directional light so that it give a little more light to the scene; just a bit, it's a night scene. :)
     
  35. UnboundGodz

    UnboundGodz

    Joined:
    Nov 15, 2017
    Posts:
    2
    Alright, I appreciate your fast response. Glad I dont need to bake them.
     
  36. steinwang

    steinwang

    Joined:
    Feb 24, 2019
    Posts:
    1
    Hi Lucas! I'm having exactly the same problem as yours. Have you solved it?
     
  37. gpdeal

    gpdeal

    Joined:
    Apr 20, 2019
    Posts:
    3
    I am trying to begin the survival shooter tutorial, but immediately upon loading the project (before making any changes), I see that the project starts off with 125 compiler errors, most of them of the form "error CS0246: The type or namespace name [some name] could not be found". I'm not familiar yet with C# (my day job is in Java), but it looks like it's having some dependency issue(s). Is this how it should be? Are these compiler errors expected until you get a ways into the tutorial? Or is this broken? I don't want to waste a bunch of time following this tutorial if the project is broken from the start.
     
  38. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    What version of Unity are you using? Where did you download the project? On the Asset Store or on the "Learn" tab in the Hub?

    I just downloaded the project in 2019.1 and I get these errors too; they are all related to the Package Manager and when I try opening it, I get a blank window.

    Fix:
    • each time you start this project, remove all the packages. Keep the project open, go to ~\Survival Shooter project\Library\PackageCache and delete all the packages are in this folder.
    • install an older version of Unity, if you are using 2019.1, version 2018.3 should work.
     
  39. gpdeal

    gpdeal

    Joined:
    Apr 20, 2019
    Posts:
    3
    Looks like that did it, thanks a lot!
     
  40. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    You're welcome! What did you choose to do?

    Normally, tutorials should be make using the version of Unity they were created with but I prefer making them with the earliest one; fixing problems is also learning. ;)
     
  41. gpdeal

    gpdeal

    Joined:
    Apr 20, 2019
    Posts:
    3
    Deleting the PackageCache contents did it! I probably should have realized that since all the errors pointed to that directory and it has 'cache' right in the name so I should have known it was safe to clear, but you never know when working in a new environment :p
     
  42. APSchmidt

    APSchmidt

    Joined:
    Aug 8, 2016
    Posts:
    3,513
    You'll have to do that each time you start the tutorial because Unity will recreate them all and the errors will come back. :)
     
  43. JoshErasmus93

    JoshErasmus93

    Joined:
    Apr 12, 2019
    Posts:
    2
    I am trying to input a question into the game and created one using UI, same scripts and UI as the live session game quiz. But when i press play the question pops up fine but wont let me click any of the buttons but the mouse still lets me fire the gun and moves the character. Any way i could pause the back round? Or input a back round/quad onto the question panel, like a new mask of some sort? So that when the question is enabled the mouse click works on the buttons! if you need any more info please ask.
     
    Last edited: May 3, 2019
  44. alex8246

    alex8246

    Joined:
    May 18, 2017
    Posts:
    1
    Hello, I am working on a project based on the code from the tutorial. There are two animations, Rifle Idle and Firing Rifle, that seem to be not transitioning properly. Video here:



    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.     public AudioSource gunAudio;
    9.     public AudioClip gunSound;
    10.  
    11.     float timer;
    12.     Ray shootRay = new Ray();
    13.     RaycastHit shootHit;
    14.     int shootableMask;
    15.     ParticleSystem gunParticles;
    16.     LineRenderer gunLine;
    17.     Light gunLight;
    18.     float effectsDisplayTime = 0.2f;
    19.     Animator anim;  //ref to animator
    20.     //bool Fire = false; //original
    21.     bool isFiring;
    22.  
    23.     void Awake ()
    24.     {
    25.         shootableMask = LayerMask.GetMask ("Shootable");
    26.         gunParticles = GetComponent<ParticleSystem> ();
    27.         gunLine = GetComponent <LineRenderer> ();
    28.         gunAudio = GetComponent<AudioSource> ();
    29.         gunLight = GetComponent<Light> ();
    30.     }
    31.  
    32.     void Start ()
    33.     {
    34.         anim = gameObject.GetComponent<Animator> ();
    35.     }
    36.    
    37.  
    38.     void Update ()
    39.     {
    40.         timer += Time.deltaTime;
    41.  
    42.         if (Input.GetButton ("Fire1") && timer >= timeBetweenBullets && Time.timeScale != 0) {
    43.             isFiring = true;
    44.             Shoot ();
    45.             anim.SetBool ("isFiring", isFiring);
    46.         } else {
    47.             isFiring = false;
    48.             anim.SetBool ("isFiring", isFiring);
    49.         }
    50.         if(timer >= timeBetweenBullets * effectsDisplayTime)
    51.         {
    52.             DisableEffects ();
    53.         }
    54.     }
    55.  
    56.  
    57.     public void DisableEffects ()
    58.     {
    59.         gunLine.enabled = false;
    60.         //gunLight.enabled = false;
    61.     }
    62.  
    63.  
    64.     void Shoot ()
    65.     {
    66.         timer = 0f;
    67.         gunAudio.clip = gunSound;
    68.         gunAudio.Play ();
    69.  
    70.         //gunLight.enabled = true;
    71.  
    72.         gunParticles.Stop ();
    73.         gunParticles.Play ();
    74.  
    75.         gunLine.enabled = true;
    76.         gunLine.SetPosition (0, transform.position);
    77.  
    78.         shootRay.origin = transform.position;
    79.         shootRay.direction = transform.forward;
    80.  
    81.         if(Physics.Raycast (shootRay, out shootHit, range, shootableMask))
    82.         {
    83.             EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth> ();
    84.             if(enemyHealth != null)
    85.             {
    86.                 enemyHealth.TakeDamage (damagePerShot, shootHit.point);
    87.             }
    88.             gunLine.SetPosition (1, shootHit.point);
    89.         }
    90.         else
    91.         {
    92.             gunLine.SetPosition (1, shootRay.origin + shootRay.direction * range);
    93.         }
    94.     }
    95. }
    96. /code]
     
    Last edited: Jun 27, 2019
  45. icdgeogames

    icdgeogames

    Joined:
    Aug 3, 2019
    Posts:
    4
    Hi guys,
    When i will finish the game after tutorials, can i share the game?
     
  46. whitefoxgamess

    whitefoxgamess

    Joined:
    Apr 14, 2019
    Posts:
    3
    hello,
    i'm new to unity,
    can someoane show/explain how to activate mobile input, or how to add it to this project please
     
  47. whitefoxgamess

    whitefoxgamess

    Joined:
    Apr 14, 2019
    Posts:
    3
    hello, i'm new to unity, can someoane show/explain how to activate mobile inputi, or how to add it to this project please
     
  48. marioipw95

    marioipw95

    Joined:
    Aug 20, 2019
    Posts:
    1
    I can not drag the Player object onto the Player Health from the Enemy Manager script but I can drag the ZombunnySpawnPoint onto the Enemy part from the Enemy Manager script, also needles to say the spawner is not working. Please help.
    Thank you in advance.
     
  49. Bud1304

    Bud1304

    Joined:
    Oct 24, 2018
    Posts:
    1
    I'm seriously struggling here just to get this started. Ten months ago I downloaded all the assets and began this project on an older computer. I quickly realized it could not handle unity and stopped there. I got a new computer today and wanted to start over. I go to the asset store and find survival shooter. I clicked the link for the assets, it goes to a page and the link says "open in Unity". Problem is, I haven't downloaded it on this new computer. Opening it in unity doesn't do anything, the launcher opens and doesn't have anything to show for this project. I have no idea what's going on. Was this pulled off the assets store or something?
     
  50. samakshkhatri14

    samakshkhatri14

    Joined:
    Sep 26, 2019
    Posts:
    1
    Can anyone help me with the ZomBear?
    It is on the Shootable layer and the bullets hit it but it is not taking any damage and neither it is attacking the player. I just copied components of the ZomBunny and everything is same including the components.

    During playing mode, there is a runtime error that pops up which shows that there is no object assigned to the Object reference created for the player in all the scripts of EnemyAttacking and EnemyHealth

    Even the animation for getting hit is not playing on the ZomBear. Please help!!!
     
unityunity