error CS0029: Cannot implicitly convert type `UnityEngine.Transform' to `UnityEngine.Camera'

Hey guys, I’m having a weird error where it is saying that i’m trying to convert one class to another. I have tried type casting it, but it still gives me the error. Any reason why this is happening? Also the error is this code line,

“Camera cameraTransform = Camera.main.transform;”

`using UnityEngine;
using System.Collections;


public class NewCameraScript : MonoBehaviour {

public AnimationClip idleAnimation;
public AnimationClip walkAnimation;
public AnimationClip runAnimation;
public AnimationClip jumpPoseAnimation;

public float walkMaxAnimation = 0.75f;
public float trotMaxAnimation = 1.0f;
public float runMaxAnimation = 1.0f;
public float jumpAnimationSpeed = 1.15f;
public float landAnimationSpeed = 1.0f;

public Animation _animation;

enum CharacterState 
    Idle = 0, 
    Walking = 1 , 
    Trotting = 2, 
    Running = 3, 
    Jumping = 4, 

private CharacterState _characterState;

float walkSpeed = 2.0f;
float trotSpeed = 4.0f;
float runSpeed = 6.0f;

float inAirControlAcceleration = 3.0f;
float jumpHeight = 0.5f;

float gravity = 20.0f;

float speedSmoothing = 10.0f;
float rotateSpeed = 500.0f;
float trotAfterSpeed = 3.0f;

bool canJump = true;

private float jumpRepeatTime = 0.05f;
private float jumpTimeout = 0.15f;
private float groundedTimeout = 0.25f;

private float lockCameraTimer = 0.0f;
private Vector3 moveDirection =;
private float verticalSpeed = 0.0f;
private float moveSpeed = 0.0f;

private CollisionFlags collisionFlags;

private bool jumping = false;
private bool jumpingReachedApex = false;

private bool movingBack = false;
private bool isMoving = false;
private float walkTimeStart = 0.0f;
private float lastJumpButtonTime = -10.0f;
private float lastJumpTime = -1.0f;

private float lastJumpstartHeight = 0.0f;

private Vector3 inAirVelocity =;

private float lastGroundTime = 0.0f;
private bool isControllable = true;

void Awake()
    moveDirection = transform.TransformDirection(Vector3.forward);

    _animation = GetComponent<Animation>();
    if (!_animation)
        Debug.Log("The character you would like to control doesn't have animations. Moving It might look weird.");

    if (!idleAnimation)
        _animation = null;
        Debug.Log("No idle animation found. Turning off animations.");
    if (!walkAnimation)
        _animation = null;
        Debug.Log("No walk animation found. Turning off animations.");
    if (!runAnimation)
        _animation = null;
        Debug.Log("No run animation found. Turning off animations.");
    if (!jumpPoseAnimation && canJump)
        _animation = null;
        Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations.");

void UpdateSmoothedMovementDirection()
   Camera cameraTransform = Camera.main.transform;

// Use this for initialization
void Start () {


// Update is called once per frame
void Update () {



The problem is because you are trying to cast a Transform to a camera. If you want the transform, then you should do:

Transform cameraTransform = Camera.main.transform;

If you want the camera component instead:

Camera camera = Camera.main;

Note I assume this is incomplete code since ‘cameraTransform’ is a local variable and you are not doing anything with it.