So… i am following this tutorial on youtube and i am getting stuck at making the camera. I have tried to add the camera script before the player script in the Script execution order but i still get the same error on line 20. When i press play the script is disabled in the inspector and when i enable it i get another error in line 42 which is added repeatedly.
Here is the camera script:
public class ThirdPersonCamera : MonoBehaviour {
[SerializeField] Vector3 cameraOffset;
[SerializeField] float damping;
Transform cameraLookTarget;
Player localPlayer;
void Awake ()
{
GameManager.Instance.OnLocalPlayerJoined += HandleOnLocalPlayerJoined;;
cameraLookTarget = localPlayer.transform.Find ("cameraLookTarget");
if (cameraLookTarget == null)
cameraLookTarget = localPlayer.transform;
}
void HandleOnLocalPlayerJoined(Player player)
{
localPlayer = player;
}
void Update ()
{
Vector3 targetPosition = cameraLookTarget.position + localPlayer.transform.forward * cameraOffset.z +
localPlayer.transform.up * cameraOffset.y +
localPlayer.transform.right * cameraOffset.x;
transform.position = Vector3.Lerp (transform.position, targetPosition, damping * Time.deltaTime);
}
}
Here is the Player script:
[RequireComponent(typeof(CharacterMovement))]
public class Player : MonoBehaviour {
[System.Serializable]
public class MouseInput{
public Vector2 Damping;
public Vector2 Sensitivity;
}
[SerializeField] float speed;
[SerializeField] MouseInput MouseControl;
private CharacterMovement m_characterMovement;
public CharacterMovement characterMovement
{
get{
if (m_characterMovement == null)
{
m_characterMovement = GetComponent<CharacterMovement> ();
}
return m_characterMovement;
}
}
InputController playerInput;
void Awake ()
{
playerInput = GameManager.Instance.inputController;
GameManager.Instance.LocalPlayer = this;
}
void Update ()
{
Vector2 direction = new Vector2 (playerInput.Vertical * speed, playerInput.Horizontal * speed);
characterMovement.Move (direction);
}
}
I am positive that the errors has to do with the “cameralooktarget” but i would like to know why and how i could fix it. Tell me if you need anymore details, any kind of help is appreciated.