Hi all I’m doing a tutorial and I’m new to unity and totally new game dev. I have no experience in coding and get confused easy. Can someone tell me what I did wrong and how to fix this? Survival Shooter Training Day Phases - Unity Learn
heres the error message I have-
Assets/Scripts/Player/PlayerMovementcode.cs(3,14): error CS0101: The namespace global::' already contains a definition for PlayerMovement’
3034382–227065–PlayerMovementcode.cs (2.53 KB)
How to fix what? What is not working? Are you getting errors or is it not behaving correctly?
Capitalisation in code is important. Check your ‘Turning’ and ‘turning’ method naming.
As a friendly heads up, scripting questions will get the most answers in the Scripting section of the forum.
Also, code should be inserted with code tags: Using code tags properly - Unity Engine - Unity Discussions
That way, your code will look like this, easy to read and no download required 
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float speed = 6f;
Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;
void Awake()
{
floorMask = LayerMask.GetMask ("Floor");
anim = GetComponent <Animator> ();
playerRigidbody = GetComponent<playerRigidbody> ();
}
void FixedUpdate()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
Turning ();
Animating (h, v);
}
void Move (float h, float v)
{
movement.set (h, 0f, v);
movement = movement.normalized * speed * Time.deltaTime;
playerRigidbody.MovePosition (transform.position + movement);
}
//C# capitalization matters a LOT, names MUST have the exact same capitalization!
void turning() //Need to capitalize this so Turning() will work
{
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);
}
}
void Animating (float h, float v)
{
bool walking = h != 0f || v != 0f;
anim.SetBool ("IsWalking", walking);
}
}
btw how I switch this over to the coding section in forums
wasn’t capitalization it seems
You could give us all a hint by telling us what is not working. Are you getting any error messages?
yes just added the message above,
Assets/Scripts/Player/PlayerMovementcode.cs(3,14): error CS0101: The namespace global::' already contains a definition for PlayerMovement’
OK, that means there’s already a class called PlayerMovement defined in another script. If you imported the tutorial assets and there is already a script called PlayerMovement there, then that would be the problem. Name yours MyPlayerMovement or something, and make sure to also rename the file to MyPlayerMovement.cs since Unity needs the filename and class name to match.
1 Like
You can’t move threads once you post them, so when you start a thread, make sure you’re on the right page.
Don’t forget that when you rename your script file name you need to rename the class name to match the file name.
how come I cant remove a script to add a new one, I’m stuck with my script I cant rename
Go to your game object with the script on it, in the Inspector click on the gear icon on the script component and hit “Remove component”. Then you can drag on your renamed script or use the add component button.
even though I remove the script from the project still cant keep it going
so how can I fix it
I did wont let me drag untilthe other one is fixed even if I removed it
What’s the error you’re getting in the Console? Please be specific!
Says- Please fix compile errors before creating new script components. That’s when I drag my new script onto my player
OK, so that means there’s an error in one of your scripts. The Console should tell you what problems there are.