Search Unity

Survival Shooter Q&A

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

  1. D3struct10n2806

    D3struct10n2806

    Joined:
    Nov 20, 2015
    Posts:
    3
    I have complete this tutorial and moved on to "Upgrading Unity 4 Audio Part 2: Snapshots and exposed parameters". They have MenuCanvas added, but I do not see a tutorial on how they have done this. Does anyone have a link or doc on creating this MenuCanvas? I am kind of stuck here as this tutorial requires this MenuCanvas that has been implemented...
     
  2. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Hey, guys. When I noticed there had been made an official Unity 5 version of this project I updated my version to include all the new changes. You can play or download it here:
    survival-shooter-3.jpg
    http://twiik.net/projects/survival-shooter-extended

    There are some other changes as well. For example you can change the waves through the inspector now rather than through code. A few people have asked me about that. And I included the pause menu I forgot the first time around.
     
    lepiyao, peteorstrike and JustinFong like this.
  3. JustinFong

    JustinFong

    Joined:
    Nov 26, 2015
    Posts:
    1
    Having trouble with downloading assets. It gets stuck at a random percentage each time I try.
    yes, i have tried restarting the program and my computer. I have tried logging out and back in. Still stuck.
     
  4. feehsilvareis

    feehsilvareis

    Joined:
    Nov 23, 2015
    Posts:
    2
    Hi, tks and congratulations for this tutorial!
    That is my first project and I don't now nothing about programming... I'll start to study programming and this tutorial helped me to understand how it works.
    But, I have a doubt (the video bellow, 5:39 min). With Unity 5, my "MenuCanvas" don't have image...

    http://unity3d.com/pt/learn/tutoria...r-beta/upgrading-4-audio-part2?playlist=17144

    When I press "esc", the game pause, but the screen of the pause with the vol control don't appear.
    I don't know how to configure it without a tutorial :p

    Can anyone help me?

    MenuCanvas.png menu.png
     
    rafaelfaturi likes this.
  5. feehsilvareis

    feehsilvareis

    Joined:
    Nov 23, 2015
    Posts:
    2
    Mee too, I'm trying by myself... but it's hard to do the part in 2D mode without coordinates. I managed to do that:

    Hierarchy: Create>UI>Canvas. Name it to "MenuCanvas".
    With the MenuCanvas selected, go to Project: Assets>_CompletedAssets>Scripts and open de folder "Managers",
    there you find the "PauseManager" and "MixLevels" (maybe MixLevels is in another audio folder... I moved it to Managers to be more simple). Drag these scripts ON "MenuCanvas".

    With it you can make part2 video until 7:50 min.

    Now, the part of the image I'm unable to do =/
    Its my first project of my life o/ hahaha

    I hope it help you.
     

    Attached Files:

  6. kettlepot

    kettlepot

    Joined:
    Nov 29, 2015
    Posts:
    2
    Made it through the tutorial! Everything seems to work, except after death, when the game restarts the lighting seems dark/off. Subsequent restarts stay dark. Based on the video, it looks like the light (original) lighting looks right. Any insight is appreciated.
     

    Attached Files:

  7. kettlepot

    kettlepot

    Joined:
    Nov 29, 2015
    Posts:
    2
    Also, has anyone successfully migrated the Survival Shooter to mobile? I found the option under "Mobile Input" to enable mobile mode in the _CompletedAssets project, but unsure how to successfully connect up the included scripts against a mobile controller (grabbed the one from standard assets).
     
  8. dgabrielsyr

    dgabrielsyr

    Joined:
    Nov 30, 2015
    Posts:
    1
    I'm new to unity and I really need help!

    Everything was working great until I got to the harming enemies section. I pasted a picture below of the error I'm having and I have no idea how to fix this. Please help!!

    -D
     

    Attached Files:

  9. Krypt2Knight

    Krypt2Knight

    Joined:
    Dec 3, 2015
    Posts:
    3
    I'm having trouble I followed everything exactly I am using Unity 5 and my Camera won't follow my player. Here is my Script:

    using UnityEngine;
    using System.Collections;
    public class CameraFollow : MonoBehaviour {

    public Transform target;
    public float smoothing = 5f;

    Vector3 offset;

    void Start()
    {
    offset = transform.position - target.position;
    }

    void FixedUpdated()
    {
    Vector3 targetCamPos = target.position + offset;
    transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
    }
    }

    I don't understand where I went wrong. and yes I did add player from the hierarchy to the target in the the Camera script component. I am getting some errors but idk if their relevant

    Integrate failed on Light Transport job.
    Failed reading from: 'aa/aa13077f9eb0b614205169478fb6f52d.taw'.
    Failed reading from: '2c/2c8c0c52f7a42154a0a25a25ad20b8de.taw'.

    These 3 repeat infinitely Please help!!!!!!!!

    Thanks in Advance
    Unity.png
     
  10. TRaging123

    TRaging123

    Joined:
    Dec 8, 2015
    Posts:
    1
    I am having problems with episode 2 and movement, I am getting an error which I've checked my code tot he tutorial and its seems the same but still an error.
    upload_2015-12-8_21-42-59.png

    my code:

    upload_2015-12-8_21-44-21.png

    the spelling and placement seem the same as the tutorial so I'm stumped, please help.
     
  11. Wieczorkowski-Rettinger

    Wieczorkowski-Rettinger

    Joined:
    Dec 10, 2015
    Posts:
    1
    I used Raw Image instead of Image and it works as shown in the videos. You just have to change any reference of type 'Image' to 'RawImage' in your scripts.
     
  12. csanborn1989

    csanborn1989

    Joined:
    Sep 9, 2015
    Posts:
    1
    So I was having the same problem and with no luck finding the answer, I was looking at your script when I noticed the issue with yours is the "void FixedUpdated()" it is supposed to be "void FixedUpdate()". So it made me look at my syntax one more time and it was a typing error as well(void FixedUpDate()). Hope This helps anyone else with the same error
     
    Last edited: Dec 12, 2015
  13. PBearGaren

    PBearGaren

    Joined:
    Sep 27, 2015
    Posts:
    2
    My issue is different. The enemy won't die when the player shoots it. Any thoughts?
     
  14. Krypt2Knight

    Krypt2Knight

    Joined:
    Dec 3, 2015
    Posts:
    3
    Thanks for the help!!! you have no clue how much that hurt to find out I was "f"ed by a "d".
     
  15. Krypt2Knight

    Krypt2Knight

    Joined:
    Dec 3, 2015
    Posts:
    3
    OK so I went through all 10 chapter and everything works as expected until I make the build. When I build it none of the enemies will come out of their spawn points. I can shot them but they just don't come after me anymore.

    OK I built it with debug mode the error I'm getting is:
    "SetDestination" can only be called on an active agent that has been placed on a NavMesh.
     
    Last edited: Dec 27, 2015
  16. xu-x

    xu-x

    Joined:
    Dec 28, 2015
    Posts:
    3
    Hey there,
    I finished all 10 chapter.
    Is there somebody has these problems?
    First, I fixed
    Code (CSharp):
    1. FindGameObjectWithTag("Player");
    which always give me a cloned player.
    by using
    Code (CSharp):
    1. FindGameObjectWithTag("Hero");
    .
    Here I added a new tag "Hero".
    Or,
    Code (CSharp):
    1. var list = GameObject.FindGameObjectsWithTag("Player")
    2.             .Cast<GameObject>()
    3.             .Where(obj => !string.IsNullOrEmpty(obj.name) && obj.name.IndexOf("Clone") == -1);
    4.         Assert.AreEqual(1, list.Count());
    5.         player = list.ElementAt(0).transform;
    Using linq but can do the same using for-loop with if-else.

    Then I fixed "GI output for inputsystem: xxxxxxxxxxxxxxxxxxxxxxxxxx (xxxxxxxxxxxxxxxxxxxxxxxxxxxxx) is missing." by unchecked auto build lightmaps.

    But, there seems still a problem with the ParticleSystem.
    It just only fires once. Both of "GunParticles" and "HitParticles"
    Before I fire, I can see the "shuriken" mark from scene window, but after I fired the mark will disappear.
    Then the particles will never show themselves again.
     
  17. VeronicaZ

    VeronicaZ

    Joined:
    Jun 12, 2010
    Posts:
    6
    Can someone tell me how to get the audio icon to not show up on my cute player when I click play?
     
  18. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
  19. VeronicaZ

    VeronicaZ

    Joined:
    Jun 12, 2010
    Posts:
    6
    *hugs TwiiK for being awesome and pushes play without icons. Thank you.
     
  20. DemiHans21

    DemiHans21

    Joined:
    Dec 31, 2015
    Posts:
    1
    I am using unity 5.3 and i got the new files for the survival shooter tutorial but when i try to type in the player movement script something goes wrong i need help i dont know if its because im using visual studio 2015 because its what pops up when i open the script what can i do iam trying to get a head start on leaning programming because i start school in a week.
     
  21. chrparrini

    chrparrini

    Joined:
    Aug 20, 2012
    Posts:
    1
    I am having a similar (if not the same) issue with the particle system. When the player shoots, if the button is held down, the "GunParticles" are emitted correctly. It works the same when the gunshot hits an enemy (if it keeps hitting them, the "HitParticles" will emit). But if you release the button and try to shoot again, or the gunshots miss the enemy and hit them just after, the particles will not appear anymore. The light effect and the line representing the raycast work just fine, but not the particles. I am doing some tests to see if this is happening because the particles were made for the Unity 4, but so far I could not find the problem.

    I am using Unity 5.3.1f1.
     
  22. xu-x

    xu-x

    Joined:
    Dec 28, 2015
    Posts:
    3
    That's exactly what I have. And I did some very simple tests to recreate this issue.
    Such as create a new scene with a MainCamera, DirectLight and an object called "ParticleSystemHolder" which like this↓,
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ParticleManagerHolder : MonoBehaviour
    5. {
    6.     ParticleSystem ptc_;
    7.  
    8.     void Awake()
    9.     {
    10.         ptc_ = GetComponent<ParticleSystem>();
    11.     }
    12.  
    13.     // Use this for initialization
    14.     void Start ()
    15.     {
    16. //        ptc_.Stop();
    17.     }
    18.  
    19.     void OnGUI()
    20.     {
    21.         if(GUI.Button(new Rect(10, 10, 50, 50), "Play"))
    22.         {
    23. //            ptc_ = GetComponent<ParticleSystem>();
    24.             ptc_.Stop();
    25. //            ptc_.Clear();
    26.             ptc_.Play();
    27.             Debug.Log("Play");
    28.         }
    29.         else if(GUI.Button(new Rect(10, 70, 50, 50), "Stop"))
    30.         {
    31. //            ptc_ = GetComponent<ParticleSystem>();
    32.             ptc_.Stop();
    33.             Debug.Log("Stop");
    34.         }
    35.     }
    36. }
    37.  
    then add a ParticleSystem component and leave the parameter as default.
    I found if I stop the ParticleSystem and play it after the last piece of particle disappeared, it will never restart again.
    And I can easily recreate it with "ParticleSystem.Clear()".
    I think the instance of ParticleSystem is killed by GC or something else.

    Finally, I create another object in SurvivalShooter to hold ParticleSystem which have "looping" and "Play On Awake" checked, so I can control particle on/off by using GameObject. SetActive(bool).

    I'm using Unity5.3.1f1, by the way.
     
    Last edited: Jan 4, 2016
  23. CannJRB

    CannJRB

    Joined:
    Jan 6, 2016
    Posts:
    9

    I know this was a while back but I had the same problem. I could not get the Player tag to work. I created my own tag and the bunny follows the player.
     
  24. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
    hello
    i'm having some camera issues...i wrote the script word to word as it was there in the tutorial but in the game view the camera is getting clipped.
    i'm posting the script and the warning with it
    Warning:
    There are inconsistent line endings in the 'Assets/_CompletedAssets/Scripts/Camera/CameraFollow.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Many text editors can fix this using Convert Line Endings menu commands.
    Script:
    using UnityEngine;
    using System.Collections;

    public class CameraFollow : MonoBehaviour
    {
    public Transform target;
    public float smoothing = 5f;

    Vector3 offset;

    void start()
    {
    offset = transform.position - target.position;
    }

    void FixedUpdate ()
    {
    Vector3 targetCamPos = target.position + offset;
    transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
    }
    }

    NOTE:

    But when i replace my script with the one given on the tutorial page the issue was gone.
     

    Attached Files:

  25. peteorstrike

    peteorstrike

    Unity Technologies

    Joined:
    Oct 4, 2013
    Posts:
    116
    Hi @hitesh3012

    From a brief scan of your code, it looks like your void start() wasn't capitalised; it should read

    Code (CSharp):
    1.  void Start ()
    2.     {
    3.         // Calculate the initial offset.
    4.         offset = transform.position - target.position;
    5.     }
    The warning itself is unrelated and nothing to worry about, though, and won't affect how your scripts run.
     
    Last edited: Jan 6, 2016
  26. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
    it worked!! thanks :D
     
    peteorstrike likes this.
  27. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
    i'm stuck on level 6 with not taking any damage from bunny...no damage image flashing...no reduction in healthslider... help me out ..didnt change the script or did anything other than instructed
    PlayerHealth:
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;
    using UnityEngine.SceneManagement;


    public class PlayerHealth : MonoBehaviour
    {
    public int startingHealth = 100;
    public int currentHealth;
    public Slider healthSlider;
    public Image damageImage;
    public AudioClip deathClip;
    public float flashSpeed = 5f;
    public Color flashColour = new Color(1f, 0f, 0f, 0.1f);


    Animator anim;
    AudioSource playerAudio;
    PlayerMovement playerMovement;
    //PlayerShooting playerShooting;
    bool isDead;
    bool damaged;


    void Awake ()
    {
    anim = GetComponent <Animator> ();
    playerAudio = GetComponent <AudioSource> ();
    playerMovement = GetComponent <PlayerMovement> ();
    //playerShooting = GetComponentInChildren <PlayerShooting> ();
    currentHealth = startingHealth;
    }


    void Update ()
    {
    if(damaged)
    {
    damageImage.color = flashColour;
    }
    else
    {
    damageImage.color = Color.Lerp (damageImage.color, Color.clear, flashSpeed * Time.deltaTime);
    }
    damaged = false;
    }


    public void TakeDamage (int amount)
    {
    damaged = true;

    currentHealth -= amount;

    healthSlider.value = currentHealth;

    playerAudio.Play ();

    if(currentHealth <= 0 && !isDead)
    {
    Death ();
    }
    }


    void Death ()
    {
    isDead = true;

    //playerShooting.DisableEffects ();

    anim.SetTrigger ("Die");

    playerAudio.clip = deathClip;
    playerAudio.Play ();

    playerMovement.enabled = false;
    //playerShooting.enabled = false;
    }


    public void RestartLevel ()
    {
    SceneManager.LoadScene (0);
    }
    }


    EnemyAttack:
    using UnityEngine;
    using System.Collections;

    public class EnemyAttack : MonoBehaviour
    {
    public float timeBetweenAttacks = 0.5f;
    public int attackDamage = 10;


    Animator anim;
    GameObject player;
    PlayerHealth playerHealth;
    //EnemyHealth enemyHealth;
    bool playerInRange;
    float timer;


    void Awake ()
    {
    player = GameObject.FindGameObjectWithTag ("Player");
    playerHealth = player.GetComponent <PlayerHealth> ();
    //enemyHealth = GetComponent<EnemyHealth>();
    anim = GetComponent <Animator> ();
    }


    void OnTriggerEnter (Collider other)
    {
    if(other.gameObject == player)
    {
    playerInRange = true;
    }
    }


    void OnTriggerExit (Collider other)
    {
    if(other.gameObject == player)
    {
    playerInRange = false;
    }
    }


    void Update ()
    {
    timer += Time.deltaTime;

    if(timer >= timeBetweenAttacks && playerInRange/* && enemyHealth.currentHealth > 0*/)
    {
    Attack ();
    }

    if(playerHealth.currentHealth <= 0)
    {
    anim.SetTrigger ("PlayerDead");
    }
    }


    void Attack ()
    {
    timer = 0f;

    if(playerHealth.currentHealth > 0)
    {
    playerHealth.TakeDamage (attackDamage);
    }
    }
    }

     

    Attached Files:

    • 1.jpg
      1.jpg
      File size:
      366.8 KB
      Views:
      792
    • 2.jpg
      2.jpg
      File size:
      356.6 KB
      Views:
      845
    • 3.jpg
      3.jpg
      File size:
      374.5 KB
      Views:
      845
    • 4.jpg
      4.jpg
      File size:
      325.1 KB
      Views:
      830
    • 5.jpg
      5.jpg
      File size:
      374.6 KB
      Views:
      844
    Last edited: Jan 6, 2016
  28. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
    cont...
     

    Attached Files:

    • 6.jpg
      6.jpg
      File size:
      376.2 KB
      Views:
      832
    • 7.jpg
      7.jpg
      File size:
      365.4 KB
      Views:
      1,105
    • 8.jpg
      8.jpg
      File size:
      325 KB
      Views:
      829
    • 9.jpg
      9.jpg
      File size:
      366.9 KB
      Views:
      825
    • 10.jpg
      10.jpg
      File size:
      353 KB
      Views:
      820
  29. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
     

    Attached Files:

    • 11.jpg
      11.jpg
      File size:
      356 KB
      Views:
      826
  30. hitesh3012

    hitesh3012

    Joined:
    Jan 6, 2016
    Posts:
    6
    i'm having issues in scripts ...at the end of tutorial 7, we had to remove the comments from the enemymovement n playershooting script...after the updation, zombunny is not following the player...and both of them are not taking any damage. help me out
     

    Attached Files:

  31. fritz-kola

    fritz-kola

    Joined:
    Jan 4, 2016
    Posts:
    12
    Edit: got it, I wrote Awake with an 'a' instead of an 'A'

    Hello guys,

    I'm trying to make the survival game, watching the tutorial. So I wrote the script as it was shown in the tutorial, but it doesn't work. I get always a NullPointerReference, when using the Move-method. The problem is, that it works with the given solution on the webpage, but I don't get the difference between that and mine, when I compare them to each other.
    Here is my script.
    Do somebody see my fault ?

    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.         floormask = LayerMask.GetMask ("Floor");
    15.         anim = GetComponent <Animator> ();
    16.         playerRigidbody = GetComponent <Rigidbody> ();
    17.  
    18.     }
    19.  
    20.     void FixedUpdate() {
    21.         float h = Input.GetAxisRaw ("Horizontal");
    22.         float v = Input.GetAxisRaw ("Vertical");
    23.  
    24.         Move (h, v);
    25.         Turning ();
    26.         Animating (h, v);
    27.  
    28.     }
    29.  
    30.     void Move(float h, float v) {
    31.         movement.Set (h, 0f, v);
    32.         movement = movement.normalized * speed * Time.deltaTime;
    33.         playerRigidbody.MovePosition(transform.position + movement);
    34.     }
    35.  
    36.     void Turning() {
    37.         Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
    38.         RaycastHit floorHit;
    39.         // camRay um Ziel des Casts zu betimmen, Speicherung der Informationen in floorHit,
    40.         // camRayLength für Range vom Raycast, floormask damit nur floormaskZiele getroffen werden können
    41.         if (Physics.Raycast (camRay, out floorHit, this.camRayLength, floormask)) {
    42.             Vector3 playerToMouse = floorHit.point - transform.position;
    43.  
    44.             playerToMouse.y = 0f;
    45.  
    46.             Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
    47.             playerRigidbody.MoveRotation (newRotation);
    48.         }
    49.     }
    50.  
    51.     void Animating(float h, float v) {
    52.         bool walking = true;
    53.         if (h != 0f || v != 0f) {
    54.             walking = true;
    55.         }
    56.  
    57.         anim.SetBool ("IsWalking", true);
    58.     }
    59. }
    60.  
     
    Last edited: Jan 12, 2016
  32. aris_tsourous

    aris_tsourous

    Joined:
    Jan 13, 2016
    Posts:
    1
    Hi guys, on 2nd tutorial, after I drag the Environment prefab into the hierarchy, just as the blue bar thingy in the bottom right corner finishes, Unity crashes. Any idea why?
    I have Unity 5.3.1f1 (32-bit) Personal on Windows 7 Ultimate SP1.
    I have deleted the Unity 5 package from the hard drive and re-downloaded from asset-store a couple of times.
    Should I just create an empty 'Environment' in the hierarchy and drag the prefab's children as its children one by one, and hope for the best?
    I just filed a bug to be sure...
     
  33. maki47

    maki47

    Joined:
    Feb 16, 2015
    Posts:
    29
    I've downloaded the new package and when I tried to import it, I got this error message: "Failed to import package with error: Couldn't decompress package UnityEditor.Web.JSProxyMgr:DoTasks()"

    Any idea what I've done wrong? I'm using Unity 5.2.0(64-bit) and OS: windows 8. I've tried to delete the package and redownload it but still the same error. I tried also to import the old package of Survival Shooter and it works well. This is very frustrating. Any help?
     
  34. googlebac

    googlebac

    Joined:
    Feb 1, 2015
    Posts:
    56
    Hi, I'm using my own humanoid character and animations for mine, the game works fine except that the animations don't play properly. the character just wobbles around like a chess piece in the T-Pose. Any ideas on a fix?
     
  35. unidad3d

    unidad3d

    Joined:
    Jan 10, 2016
    Posts:
    30

    In the Particle System component change the "Simulation Space" from Local to World. :cool:
     
    Last edited: Jan 15, 2016
  36. Gnick Gnack

    Gnick Gnack

    Joined:
    Jan 17, 2016
    Posts:
    1
    i noticed my bunny would not move. i changed FindGameObject to Find
    still no movement.
    i took the if then statement out by "//" the lines dealing with it and it now works, the bunnies follow
     
  37. Tyranosaw

    Tyranosaw

    Joined:
    Jan 20, 2016
    Posts:
    2
    Hey Guys,

    I am on chapter 2 and finished the player movement script. My character points at my mouse fine but it doesn't follow it. eg. w will always move the character up even if its facing in a completely different direction.

    My Code

    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.  
    17.         anim = GetComponent <Animator> ();
    18.         playerRigidbody = GetComponent <Rigidbody> ();
    19.     }
    20.  
    21.  
    22.     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.     void Move (float h, float v)
    33.     {
    34.         movement.Set (h, 0f, v);
    35.  
    36.         movement = movement.normalized * speed * Time.deltaTime;
    37.         playerRigidbody.MovePosition (transform.position + movement);
    38.     }
    39.  
    40.     void Turning() {
    41.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    42.         Debug.Log("camRay "+camRay);
    43.         RaycastHit floorHit;
    44.  
    45.         if(Physics.Raycast(camRay, out floorHit, camRayLength, floorMask)){
    46.             Vector3 playerToMouse = floorHit.point - transform.position;
    47.             playerToMouse.y = 0f;
    48.             Debug.Log("playerToMouse "+playerToMouse);
    49.  
    50.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    51.             Debug.Log("newRotation "+newRotation);
    52.  
    53.             playerRigidbody.MoveRotation(newRotation);
    54.             Debug.Log("PlayerRigidBody "+playerRigidbody);
    55.         }
    56.         else
    57.             Debug.Log("ray didnt hit");
    58.     }
    59.  
    60.     void Animating (float h, float v)
    61.     {
    62.         bool walking = h != 0f || v != 0f;
    63.  
    64.         anim.SetBool ("IsWalking", walking);
    65.     }
    66. }
     
  38. lepiyao

    lepiyao

    Joined:
    May 19, 2015
    Posts:
    1
    Hey Guys,

    I am on chapter 2 and finished the CameraFollow script. When I play it through the Unity Apps the camera follow the player, but when I build it into a PC,Mac & Linux Standalone the camera won't follow my player instead of not moving from the First time player spawn (0,0,0)...Please help me about this, I already checked it over and over, and still don't find any clue whats's wrong with it...

    My Code

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraFollow : MonoBehaviour {
    5.  
    6.     public Transform target; // The position that that camera will be following.
    7.     public float smoothing = 5f; // The speed with which the camera will be following.
    8.  
    9.     Vector3 offset;  // The initial offset from the target.
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         offset = transform.position - target.position;
    14.     }
    15.    
    16.     // Update is called once per frame
    17.     void FixedUpdate ()
    18.     {
    19.         Vector3 targetCamPos = target.position + offset;
    20.         // Create a postion the camera is aiming for based on the offset from the target.
    21.  
    22.         transform.position = Vector3.Lerp(transform.position, targetCamPos, smoothing * Time.deltaTime);
    23.         // Smoothly interpolate between the camera's current position and it's target position.
    24.     }
    25. }
     
  39. kicker10bog

    kicker10bog

    Joined:
    Jan 20, 2016
    Posts:
    3
    For anyone having trouble with the enemy not following the player, the reason is that, for some reason, the game is creating an invisible clone of the Player and tagging it as "Player" ... There are a couple of workarounds and a fix.

    The workarounds have already been mentioned.
    1) use
    Code (CSharp):
    1. player = GameObject.Find("Player").transform;
    instead of
    Code (CSharp):
    1. player = GameObject.FindGameObjectWithTag("Player").transform;
    2) Change the tag to something like "Hero"

    These two workarounds get the game working, but I found that installing the second patch for 5.3.1 is what actually fixes the issue.

    On a bit of a side note, there is no documentation for GameObject.FindGameObjectWithTag, but there is for GameObject.FindGameObjectsWithTag, which returns an array of objects with the specified tag.
     
    Last edited: Jan 23, 2016
  40. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    So I'm having a problem on chapter 2. I just finished it and went to hit play to test it out, and I can't move or turn at all. And once I start to run the game I get a build up of the same error on line 36

    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 camRaylenght = 100f;
    12.  
    13.     void awake()
    14.     {
    15.         floorMask = LayerMask.GetMask ("floor");
    16.         anim = GetComponent <Animator> ();
    17.         playerRigidbody = GetComponent <Rigidbody> ();
    18.     }
    19.  
    20.     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.  
    34.         movement = movement.normalized * speed * Time.deltaTime;
    35.  
    36.         playerRigidbody.MovePosition (transform.position + movement);
    37.     }
    38.  
    39.     void Turning()
    40.     {
    41.         Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
    42.  
    43.         RaycastHit floorHit;
    44.  
    45.         if(Physics.Raycast(camRay, out floorHit, camRaylenght, floorMask))
    46.             {
    47.             Vector3 playerToMouse = floorHit.point - transform.position;
    48.             playerToMouse.y = 0f;
    49.  
    50.             Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
    51.             playerRigidbody.MoveRotation (newRotation);
    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.  
    And this is the error I keep getting!

    NullReferenceException: Object reference not set to an instance of an object
    PlayerMovement.Move (Single h, Single v) (at Assets/Scripts/Player/PlayerMovement.cs:36)
    PlayerMovement.FixedUpdate () (at Assets/Scripts/Player/PlayerMovement.cs:25)

    If anyone can help I would appreciate it a lot, thanks!
     
  41. unidad3d

    unidad3d

    Joined:
    Jan 10, 2016
    Posts:
    30
    Don't know if this will fix your problem, but

    Code (CSharp):
    1. void awake()
    2.  
    3.  
    4. should be
    5.  
    6.  
    7. void Awake()
     
  42. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    Thank you This worked! I'm always missing my capitalization errors
     
  43. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    [EDIT] Found the problem here, "Floor" on line 15 needed to be capitalized

    So now I got my player moving and the animations are working fine, but I can't turn the player at all.

    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.     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.  
    34.         movement = movement.normalized * speed * Time.deltaTime;
    35.  
    36.         playerRigidbody.MovePosition (transform.position + movement);
    37.     }
    38.  
    39.     void Turning()
    40.     {
    41.         // Create a ray from the mouse cursor on screen in the direction of the camera.
    42.         Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
    43.  
    44.         // Create a RaycastHit variable to store information about what was hit by the ray.
    45.         RaycastHit floorHit;
    46.  
    47.         // Perform the raycast and if it hits something on the floor layer...
    48.         if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
    49.         {
    50.             // Create a vector from the player to the point on the floor the raycast from the mouse hit.
    51.             Vector3 playerToMouse = floorHit.point - transform.position;
    52.  
    53.             // Ensure the vector is entirely along the floor plane.
    54.             playerToMouse.y = 0f;
    55.  
    56.             // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
    57.             Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
    58.  
    59.             // Set the player's rotation to this new rotation.
    60.             playerRigidbody.MoveRotation (newRotation);
    61.         }
    62.     }
    63.  
    64.     void Animating(float h, float v)
    65.     {
    66.         bool walking = h != 0f || v != 0f;
    67.         anim.SetBool ("IsWalking", walking);
    68.     }
    69. }
    70.  
    It at least looks like my code is right so I'm thinking that it might be a problem with my floor quad. Could that be it?
     
    Last edited: Jan 25, 2016
  44. technano

    technano

    Joined:
    Jan 13, 2016
    Posts:
    23
    So something very strange happened after I finished lesson #6, The game reset all by itself and it started playing the completed version of the game. Like with the gun working, multiple enemies coming at me and them taking damage. The only thing that didn't work was the camera! No idea why any of that would happen. Does anyone else know why?
     
  45. xu-x

    xu-x

    Joined:
    Dec 28, 2015
    Posts:
    3
    awsome! It worked.
    Thank you
     
  46. unidad3d

    unidad3d

    Joined:
    Jan 10, 2016
    Posts:
    30
    Remember this is a temporary fix, this problem is caused by a bug that will be fixed on next unity version. Keep that in mind.
     
  47. zarnes

    zarnes

    Joined:
    Jan 19, 2016
    Posts:
    7
    Hello everyone, I'm having an issue at the chapter 2, my character can't rotate by aiming with my mouse, seems that some people here have the same problem, did you find a solution ? I can't access to the debug.log command because I have :
    "NullReferenceException: Object reference not set to an instance of an object
    PlayerMovement.Turning () (at Assets/Scripts/Player/PlayerMovement.cs:41)
    PlayerMovement.FixedUpdate () (at Assets/Scripts/Player/PlayerMovement.cs:26)"

    So I think the function is stopped before display logs. I tried to recreate the floor, to log directly the command, nothing works :c.
    Here is my code but it's the same as the tutorials ones :

    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 camRayLenght = 100f;
    12.  
    13.     void Awake()
    14.     {
    15.         floorMask = LayerMask.GetMask("Floor");
    16.         anim = GetComponent<Animator>();
    17.         playerRigidbody = GetComponent <Rigidbody> ();
    18.     }
    19.  
    20.     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.  
    34.         movement = movement.normalized * speed * Time.deltaTime;
    35.  
    36.         playerRigidbody.MovePosition(transform.position + movement);
    37.     }
    38.  
    39.     void Turning()
    40.     {
    41.         Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);
    42.         Debug.Log("camRay " + camRay); //
    43.         RaycastHit floorHit;
    44.  
    45.         if(Physics.Raycast (camRay, out floorHit, camRayLenght, floorMask))
    46.         {
    47.             Vector3 playerToMouse = floorHit.point - transform.position;
    48.             playerToMouse.y = 0f;
    49.             Debug.Log("playerToMouse " + playerToMouse); //
    50.  
    51.             Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
    52.             Debug.Log("newRotation " + newRotation); //
    53.  
    54.             playerRigidbody.MoveRotation(newRotation);          
    55.             Debug.Log("PlayerRigidBody " + playerRigidbody); //
    56.         }
    57.         else
    58.             Debug.Log("bugay");
    59.     }
    60.  
    61.     void Animating(float h, float v)
    62.     {
    63.         bool walking = h != 0f || v != 0f;
    64.  
    65.         anim.SetBool("IsWalking", walking);
    66.     }
    67. }
    68.  
    Hope there is a solution, have a good day :]
     
  48. unidad3d

    unidad3d

    Joined:
    Jan 10, 2016
    Posts:
    30

    Probably it's not the solution to your problem but did you add the animation controller (PlayerAC) from the Animation folder to the player model?

    Anyway, if this does not solve your problem copy/paste the code from this page:
    http://unity3d.com/es/learn/tutorials/projects/survival-shooter/player-character?playlist=17144

    that way you will be 100% sure your code will be the correct one.
     
  49. blitzuk

    blitzuk

    Joined:
    Feb 2, 2016
    Posts:
    3
    Did you solve it?

    I see you misspelt length float camRayLenght = 100f;
     
  50. blitzuk

    blitzuk

    Joined:
    Feb 2, 2016
    Posts:
    3