- Home /
C# Third Person Controller CS1061
Following a tutorial on creating a third person controller and I'm stuck on this error:
"Assets/Scripts/Character/PlayerMotor.cs(91,40): error CS1061: Type PlayerCamera' does not contain a definition for
CameraState' and no extension method CameraState' of type
PlayerCamera' could be found (are you missing a using directive or an assembly reference?)"
I'm following the exact scripting for the problem area and I don't know why I have this error.
Script where the error is located:
using UnityEngine;
using System.Collections;
using Helper;
/// <summary>
/// This script is included with the PlayerCharacter script includes & governs the behaviors of this instance's
/// ability to move around the enviornment and animate it's model based on human input.
/// </summary>
public class PlayerMotor : MonoBehaviour
{
#region Public Fields & Properties
public float walkSpeed = 3f;
public float runSpeed = 5f;
public float sprintSpeed = 7f;
private float _rotationSpeed = 140f;
public float jumpHeight = 10f;
public float gravity = 20f;
#endregion
#region Private Fields & Properties
private float _horizontal = 0f;
private float _vertical = 0f;
private float _moveSpeed;
private float _airVelocity = 0f;
private Transform _myXform;
private Vector3 _moveDirection = Vector3.zero;
private CharacterController _controller;
private Animator _animator;
private SpeedState _speedState = SpeedState.Run;
private CameraState _cameraState;
private PlayerCharacter _pc;
private PlayerCamera _camera;
#endregion
#region Getters & Setters
///<summary>
/// Gets or sets the move speed.
/// </summary>
/// <value>
/// The move speed
/// </value>
public float MoveSpeed
{
get{return _moveSpeed;}
set{_moveSpeed = value;}
}
#endregion
#region System Methods
// Use this for initialization
private void Start ()
{
if(networkView.isMine || Network.peerType == NetworkPeerType.Disconnected)
{
//Chache references to child components of this gameObject.
_myXform = this.GetComponent<Transform>();
_pc = this.GetComponent<PlayerCharacter>();
_camera = this.GetComponent<PlayerCamera>();
_animator = _pc.Animator;
_controller = _pc.Controller;
}
else
{
enabled = false;
}
}
// Update is called once per frame
private void Update ()
{
_cameraState = _camera.CameraState;
switch(_cameraState)
{
case CameraState.Normal:
//Allow the player to rotate their character.
if(Input.GetAxis(PlayerInput.Horizontal) > 0.1f || Input.GetAxis(PlayerInput.Horizontal) < -0.1f)
{
_myXform.Rotate(0f, Input.GetAxis(PlayerInput.Horizontal) * _rotationSpeed * Time.deltaTime, 0f);
}
break;
case CameraState.Target:
break;
}
}
#endregion
#region Custom Methods
private void CalculateSpeed()
{
switch(_speedState)
{
case SpeedState.Walk:
_moveSpeed = walkSpeed;
break;
case SpeedState.Run:
_moveSpeed = runSpeed;
break;
case SpeedState.Sprint:
_moveSpeed = sprintSpeed;
break;
}
}
#endregion
}
Helper Script:
enter code hereusing UnityEngine;
using System.Collections;
namespace Helper
{
#region Reference Cache
public class PlayerInput
{
public static string Horizontal = "Horizontal";
public static string Vertical = "Vertical";
public static string Jump = "Jump";
}
public class GameTag
{
// System Tags
public static string Untagged = "Untagged";
public static string Respawn = "Respawn";
public static string Finish = "Finish";
public static string EditorOnly = "EditorOnly";
public static string MainCamera = "MainCamera";
public static string Player = "Player";
public static string GameController = "GameController";
public static string PlayerCamera = "PlayerCamera";
}
public class Resource
{
public static string AnimatorController = "System/PlayerAnimator";
}
public static class AnimatorConditions
{
public static string Speed = "Speed";
public static string Direction = "Direction";
public static string Grounded = "Grounded";
public static string AirVelocity = "AirVelocity";
}
#endregion
#region FSN Numerations
public enum CameraState
{
Normal,
Target
}
public enum SpeedState
{
Walk,
Run,
Sprint
}
#endregion
#region Object Structures
public struct CameraTargetObject
{
private Vector3 position;
private Transform xForm;
public Vector3 Position
{
get{return position;}
set{position = value;}
}
public Transform XForm
{
get{return xForm;}
set{xForm = value;}
}
public void Init(string camName, Vector3 pos, Transform transform, Transform parent)
{
position = pos;
xForm = transform;
xForm.name = camName;
xForm.parent = parent;
xForm.localPosition = Vector3.zero;
xForm.localPosition = position;
}
}
public struct CameraMountPoint
{
private Vector3 position;
private Transform xForm;
public Vector3 Position
{
get{return position;}
set{position = value;}
}
public Transform XForm
{
get{return xForm;}
set{xForm = value;}
}
public void Init(string camName, Vector3 pos, Transform transform, Transform parent)
{
position = pos;
xForm = transform;
xForm.name = camName;
xForm.parent = parent;
xForm.localPosition = Vector3.zero;
xForm.localPosition = position;
}
}
#endregion
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do I "trickle" a function's effect over n seconds? 2 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
AI help (C) 0 Answers
Using the "ThirdPersonController" Script without its Camera? 0 Answers