I changed the naming of variables in my code to the same as in the code directly from the course and now I get a few errors. both are cameraRaycaster.layerHit is inacessible due to it’s protection level (39,52) and (40,29). Here is the script:
using System;
using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityStandardAssets.Characters.ThirdPerson;
[RequireComponent(typeof (ThirdPersonCharacter))]
public class PlayerMovement : MonoBehaviour
{
[SerializeField] float walkMoveStopRadius = 0.25f;
ThirdPersonCharacter Character; // A reference to the ThirdPersonCharacter on the object
CameraRaycaster cameraRaycaster;
Vector3 currentClickTarget;
bool isInDirectMode = false;
private void Start()
{
cameraRaycaster = Camera.main.GetComponent<CameraRaycaster>();
Character = GetComponent<ThirdPersonCharacter>();
currentClickTarget = transform.position;
}
// Fixed update is called in sync with physics
private void FixedUpdate()
{
if (Input.GetKeyDown(KeyCode.G)) {
isInDirectMode = !isInDirectMode;
currentClickTarget = transform.position; //clears target
}
if (isInDirectMode) {
ProcessDirectMovement ();
} else {
if (Input.GetMouseButton (0)) {
print ("Cursor raycast hit " + cameraRaycaster.layerHit);
switch (cameraRaycaster.layerHit) {
case Layer.Walkable:
currentClickTarget = cameraRaycaster.hit.point;
break;
case Layer.Enemy:
print ("Not moving to enemy");
break;
default:
print ("SHOULDN'T BE HERE");
return;
}
}
var playerToClickPoint = currentClickTarget - transform.position;
if (playerToClickPoint.magnitude >= walkMoveStopRadius) {
Character.Move (currentClickTarget - transform.position, false, false);
} else {
Character.Move (Vector3.zero, false, false);
}
}
}
private void ProcessDirectMovement() {
print ("Direct Movement");
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 CamForward = Vector3.Scale (Camera.main.transform.forward, new Vector3 (1, 0, 1)).normalized;
Vector3 Move = v * CamForward + h * Camera.main.transform.right;
Character.Move (Move, false, false);
}
//TODO Fix Nullreference exception reference not set to instance of object
// line 45 playermovement.fixedupdate.
}