Search Unity

Survival Shooter Q&A

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

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

    cutesparkles1239

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

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

    elfxiong

    Joined:
    Jun 16, 2015
    Posts:
    2
    I'm getting a null reference exception when doing the tutorial. Each time I shoot the bunny, it generates an exception.

    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)

    The bunny's health would decrease and it would stop moving when health was 0, but the animation is still walking animation.

    Any idea what's going on?
     
    Justin11111 likes this.
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Null reference means you are missing a reference. I don't know this project well off the top of my head, but check that all of your variables are populated with the correct references. If there is a "slot" in the inspector, make sure it's filled.
     
  4. LittleWolf

    LittleWolf

    Joined:
    Jun 17, 2015
    Posts:
    3
    I had the same problem, and that worked for me, too. I'm not sure why, but what I think happened is I maybe accidentally set the floor quad scale to (100, 100, 0). It should, of course, be (100, 100, 1), despite the fact that it's essentially a two-dimensional object. Like I say, I don't remember, but setting the Z-scale to 0 certainly does have the same wrong behaviour.
     
  5. Granoia

    Granoia

    Joined:
    Jun 21, 2015
    Posts:
    1
    Hi there,

    I'm sure this is going to end up being a silly mistake since I don't see anyone else having this problem in the thread, but I'm at the end of Phase 3 and I'm having issues with Player Rotation. Namely, my Player Object does not rotate to face the mouse (or at all) when I hit Play. I've copy-pasted the example code from the tutorial for my scripts to make sure that I didn't just mess up copying somewhere but it still does not work. Any suggestions?
     
  6. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    This has been raised earlier in the thread. It seems to have been caused mainly by the wrong layer setting for the 'Floor' object - the Quad named 'Floor'100,100,0 created in the first tutorial. You must select 'floor' as the option in the Layer selectbox that is to the right of the Tag selectbox of the Inspector window when creating the floor. (This does NOT refer to the floor component within the Environment object.

    U_nitty :)

    PS This has to do with the raycast needing to 'reflect' from the floor level, I think :)
     
  7. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    Using Version 5.1.1f1.

    "null reference exception, object reference not set to an instance of an object"

    I found this error occurring due to my having accidentally duplicated the 'GameOverManager (Script)' entry in the HUDCanvas Inspector.

    Deleting the 2nd instance solved the problem.

    Surely it should not be possible to do this by accident !

    Following/Reviewing a tutorial it's easy to do a recommended step twice sadly.


    U_nitty
     
  8. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    I tried this fix and I now have an error :

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

    I commented out the function RestartLevel from PlayerHealth script, but did not delete the the transition event. Do you think that I should delete the transition event now ?

    U_nittty
     
  9. marceloclp

    marceloclp

    Joined:
    Jun 23, 2015
    Posts:
    1
    So, I started this project today. I am using the latest version of Unity, so I think that's why this is not working correctly. I am sure I coded everything correctly.



    When I hit play, that weird thing cuts half of my screen. I have no idea what it is. Is this common on this project, is this common overall or did I just messed up really bad at some point?

    EDIT: nevermind, I found the error. I used x = y = z instead of x = y - z.
     
    Last edited: Jun 23, 2015
  10. Nibz328

    Nibz328

    Joined:
    Jun 27, 2015
    Posts:
    1
    I'm using Unity 5, and I'm up to stage 6.
    My player health file is attached. It says in unity there is an error called:
    Assets/Scripts/Player/PlayerHealth.cs(5,14): error CS0101: The namespace `global::' already contains a definition for `PlayerHealth'

    Can you plz check my script and tell me what I did wrong?
    THANK YOU :D
    (error is in line 5 :D)
     

    Attached Files:

  11. Lan01

    Lan01

    Joined:
    Jun 26, 2015
    Posts:
    1
    So I have a problem, it turns out that the box colliders from LevelExtent (in enviroment) doesn't seem to work. My player keeps getting out of the play area and I can't get him back. I've already try to make the colliders bigger but still doesn't work. By the way apparently the navmesh does detect the collider because the bunnys aren't able to go through.

    P.S. Pardon my English.
     
  12. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    I've followed the Survival Shooter tutorial videos and got the game to work...

    However when it ends by the player dying, it restarts without showing game over sequence.
    The GameOver animation works when I drag the playhead (red-line), but I cannot work out why it will not fire when the game ends !

    Using version 5.1.1f1 in Win 7.

    Are there any strategies I should adopt to find the problem ?

    U_nitty
     
  13. lazerblade01

    lazerblade01

    Joined:
    Apr 12, 2014
    Posts:
    1

    I'm seeing this same exact thing. Where is this magical x = y - z supposed to go? I don't recall typing that particular line anywhere in Monoscript or any of the parameters within Unity.

    EDIT: Nevermind. My issue was a failure in capitalization - in this case, the void Start() (I typed start instead of Start).
     
    Last edited: Jun 30, 2015
  14. rahuxx

    rahuxx

    Joined:
    May 8, 2009
    Posts:
    537
    what are the NavMesh settings for this project for under unity 5.1.1p2?
     
  15. Carta

    Carta

    Joined:
    Jun 29, 2015
    Posts:
    1
    Hi I'm Daniele
    I'm on Step 2 of the Sharp Shooter tutorial. after completing the script PlayerMovement i returned in Unity, I press play and i can move my player but he doesn't follow the mouse. There are no errors in the script,
    Can someone please help me?
     
  16. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    to Carta (Daniele)

    See my reply at #156 above. This seems to be related to the 'Floor' and not setting the 'Level' correctly

    U_nitty
     
  17. U_nitty

    U_nitty

    Joined:
    Mar 8, 2015
    Posts:
    15
    See my comment/question above at #162.

    I've now got the GameOver sequence to execute by cheating.
    I've added a 2nd. parameter 'PlayerDead' to the GameOver animation.
    Now when the player dies - the GameOver animation works and afterwards the game restarts.

    Why did that works ? Why is my 'GameOver' trigger not linked to the animation ?

    ...... 'shakes his head slowly and walks into a dark corner' .........................

    U_nitty
     
  18. midomady304

    midomady304

    Joined:
    Jun 29, 2015
    Posts:
    7
    i can't be turning with mouse please help me !! (
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public float speed = 6f; // The speed that the player will move at.

    Vector3 movement; // The vector to store the direction of the player's movement.
    Animator anim; // Reference to the animator component.
    Rigidbody playerRigidbody; // Reference to the player's rigidbody.
    int floorMask; // A layer mask so that a ray can be cast just at gameobjects on the floor layer.
    float camRayLength = 100f; // The length of the ray from the camera into the scene.

    void Awake ()
    {
    // Create a layer mask for the floor layer.
    floorMask = LayerMask.GetMask ("Floor");

    // Set up references.
    anim = GetComponent <Animator> ();
    playerRigidbody = GetComponent <Rigidbody> ();
    }


    void FixedUpdate ()
    {
    // Store the input axes.
    float h = Input.GetAxisRaw ("Horizontal");
    float v = Input.GetAxisRaw ("Vertical");

    // Move the player around the scene.
    Move (h, v);

    // Turn the player to face the mouse cursor.
    Turning ();

    // Animate the player.
    Animating (h, v);
    }

    void Move (float h, float v)
    {
    // Set the movement vector based on the axis input.
    movement.Set (h, 0f, v);

    // Normalise the movement vector and make it proportional to the speed per second.
    movement = movement.normalized * speed * Time.deltaTime;

    // Move the player to it's current position plus the movement.
    playerRigidbody.MovePosition (transform.position + movement);
    }

    void Turning ()
    {
    // Create a ray from the mouse cursor on screen in the direction of the camera.
    Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);

    // Create a RaycastHit variable to store information about what was hit by the ray.
    RaycastHit floorHit;

    // Perform the raycast and if it hits something on the floor layer...
    if(Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
    {
    // Create a vector from the player to the point on the floor the raycast from the mouse hit.
    Vector3 playerToMouse = floorHit.point - transform.position;

    // Ensure the vector is entirely along the floor plane.
    playerToMouse.y = 0f;

    // Create a quaternion (rotation) based on looking down the vector from the player to the mouse.
    Quaternion newRotation = Quaternion.LookRotation (playerToMouse);

    // Set the player's rotation to this new rotation.
    playerRigidbody.MoveRotation (newRotation);
    }
    }

    void Animating (float h, float v)
    {
    // Create a boolean that is true if either of the input axes is non-zero.
    bool walking = h != 0f || v != 0f;

    // Tell the animator whether or not the player is walking.
    anim.SetBool ("IsWalking", walking);
    }
    }
     
  19. Aurore

    Aurore

    Director of Real-Time Learning

    Joined:
    Aug 1, 2012
    Posts:
    3,106
    Last edited: Jul 3, 2015
Thread Status:
Not open for further replies.