Hello I was following a youtube tutorial and I got the error in the title. Unity says the error is on line (55,10)
I was hoping someone could provide an explanation on how to fix it.
Youtube Tutorial:
https://www.youtube.com/watch?v=yWHqZoXJJ_E&list=PLdPQ93duD7PCkWpTo4ElrWlyx6S9bF18V&index=2&ab_channel=passivestar
Full Error: Assets\scripts\Player.cs(55,10): error CS0111: Type 'Player' already defines a member called 'UpdateLook' with the same parameter types
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
[SerializeField] Transform cameraTransform;
[SerializeField] float movementSpeed = 5f;
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float mass = 1f;
[SerializeField] float mouseSensitivity = 3f;
CharacterController controller;
Vector2 look;
Vector3 velocity;
PlayerInput playerInput;
InputAction moveAction;
InputAction lookAction;
InputAction jumpAction;
void Awake()
{
controller = GetComponent();
playerInput = GetComponent();
moveAction = playerInput.actions["move"];
lookAction = playerInput.actions["look"];
jumpAction = playerInput.actions["jump"];
}
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
UpdateMovement();
UpdateLook();
UpdateGravity();
}
void UpdateGravity()
{
var gravity = Physics.gravity * mass * Time.deltaTime;
velocity.y = controller.isGrounded ? -1f : velocity.y + gravity.y;
}
void UpdateMovement()
{
var moveInput = moveAction.ReadValue();
var input = new Vector3();
input += transform.forward * moveInput.y;
input += transform.right * moveInput.x;
input = Vector3.ClampMagnitude(input, 1f);
var jumpInput = jumpAction.ReadValue();
if (jumpInput > 0 && controller.isGrounded)
{
velocity.y += jumpSpeed;
}
controller.Move((input * movementSpeed + velocity) * Time.deltaTime);
}
void UpdateLook()
{
var lookInput = lookAction.ReadValue();
look.x += lookInput.x * mouseSensitivity;
look.y += lookInput.y * mouseSensitivity;
look.y = Mathf.Clamp(look.y, -89f, 89f);
transform.localRotation = Quaternion.Euler(0, look.x, 0);
cameraTransform.localRotation = Quaternion.Euler(-look.y, 0, 0);
}
},I have this error when following a youtube tutorial. I have copied the code perfectly and I was wondering if someone can give an explanation on how I can fix this error.
Here is the youtube video:
[Youtube video][1]
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
[SerializeField] Transform cameraTransform;
[SerializeField] float movementSpeed = 5f;
[SerializeField] float jumpSpeed = 5f;
[SerializeField] float mass = 1f;
[SerializeField] float mouseSensitivity = 3f;
CharacterController controller;
Vector2 look;
Vector3 velocity;
PlayerInput playerInput;
InputAction moveAction;
InputAction lookAction;
InputAction jumpAction;
void Awake()
{
controller = GetComponent();
playerInput = GetComponent();
moveAction = playerInput.actions["move"];
lookAction = playerInput.actions["look"];
jumpAction = playerInput.actions["jump"];
}
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
UpdateMovement();
UpdateLook();
UpdateGravity();
}
void UpdateGravity()
{
var gravity = Physics.gravity * mass * Time.deltaTime;
velocity.y = controller.isGrounded ? -1f : velocity.y + gravity.y;
}
void UpdateMovement()
{
var moveInput = moveAction.ReadValue();
var input = new Vector3();
input += transform.forward * moveInput.y;
input += transform.right * moveInput.x;
input = Vector3.ClampMagnitude(input, 1f);
var jumpInput = jumpAction.ReadValue();
if (jumpInput > 0 && controller.isGrounded)
{
velocity.y += jumpSpeed;
}
controller.Move((input * movementSpeed + velocity) * Time.deltaTime);
}
void UpdateLook()
{
var lookInput = lookAction.ReadValue();
look.x += lookInput.x * mouseSensitivity;
look.y += lookInput.y * mouseSensitivity;
look.y = Mathf.Clamp(look.y, -89f, 89f);
transform.localRotation = Quaternion.Euler(0, look.x, 0);
cameraTransform.localRotation = Quaternion.Euler(-look.y, 0, 0);
}
}
[1]: https://www.youtube.com/watch?v=yWHqZoXJJ_E&list=PLdPQ93duD7PCkWpTo4ElrWlyx6S9bF18V&index=2&ab_channel=passivestar
↧