For those of you wishing to follow the Survival Shooter tutorial with Unity 5, we have created a new version of the Project assets, along with an upgrade guide located in the root of the project.
We are busy making new projects so have not created new videos, but simply given you a guide to where in the videos you will need to do something different to the instructions onscreen.
As you’ll see from the guide, not much has changed and a lot of the difficulties those of you trying to run the tutorial in 5.x have been experiencing were actually with the source assets, so that’s all taken care of.
See the usual project page for a link to the new project on the Asset store which has everything you need.
We recommend that you use the Unity version we tested this with or greater - Unity 5.1.1.
Thanks for Peet Lee (peteorstrike) from our team for taking care of this!
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);
}
}
Also note, that the easiest way to debug your application is to print your variables and find exactly where the problem is. Try using sample code bellow for your turning function. When you find anything odd in the console (‘null’ being printed etc.) just click on that line. The editor should open your MonoDevelop at the line where the print was done.
I’m trying to solve this issue to no avail and I’m getting quite desperate. Since the Environment is being stored within the assets as a prefab (not a model), I’m not able to access Model tab in my inspector.
@rePhat - did you download the new Unity 5 version of the project and have this problem? very surprised as we’ve not seen this issue - which version of Unity are you seeing it with? remember we suggest Unity 5.1.1 or greater and the assets are setup for that.
Hello @rePhat ! That’s one of the main issues I wanted to get this update out to solve, so hopefully with the new assets and upgrade guide you should be good to go!
Thank you so much for this! It arrived just at the right time. Loving the learning journey.
I noticed a small mistake in the “04. CREATING ENEMY #1” Section of the PDF. The second paragraph indicates the time 01:20. It should be 11:20. It’s obvious once you get to that part but for it could be confusing for some folks who are not paying enough attention.
Again, thanks for the help with this. Here’s hoping to see new tutorials soon!
gilkzxc said
i’m sorry for asking too many questions but… something weird happend after i finished chapter 6 and everything worked fine the backgroung and the scene setting… disappeared… sort of…
I am getting the same problem. Different from the other black scene issue. The background is black at the very start. Firing does provide lighting up the areas. So i guess it is a lightning problem, but appears at it should after you die once. So if i add lightning, i am over compensating after player respawn.
I had that same problem a couple of minutes ago. After some searching on the forums, found out that apparently there’s a bug where the Editor fails to bake the lights after Application.Loadlevel. To fix it, go to Window > Lighting > Lightmaps Tab and uncheck “Auto” to avoid continuous baking and then press Build.
@midomady304 I’m seeing just two variables and its not obvious which are theese… Its generally good to print the same text, like your variable name in order to avoid confusion. The most important one for this particular task is your RigidBody., and therefore I have to ask you again, did u set your reference in the Awake() function?
I would like to point out a possible issue or bug in the C# script for “Creating Enemy #1” of the tutorial.
This person’s post from the old closed thread helped me get it working where the enemy just moved to the center of the level and stayed there moving and did not follow the player.
player = GameObject.FindGameObjectWithTag ("Player").transform;
to
player = GameObject.Find ("Player").transform;
and it works, the enemy follows the player character
I also notice that the summary tooltip description in MonoDevelop-Unity for Find has a description of what it does, “Finds a game object by name and returns it” but the FindGameObjectWithTag does not have a summary tooltip
I have not yet made a full game using Tags all the way through in code but this would be a problem. Perhaps I need to work more with Tags in code to see them working. If I encounter anymore of these issues I will let Unity know somehow.
@jaimemh - thanks we’ve now updated the PDF, appreciate the help. @uni00 - thanks for pointing this out but not sure why it would not be working with tag, as the Player tag a) always exists in Unity projects and b) should be assigned to the player character during the tutorial.