Hello. I'm new at Unity 3D and I try to make some game by watchinng tutorials for begginers. And now I have error on one of the lines, I dont know how to explain that and hot to fix that. Please help me if you can . Sorry for my bad english There is a photos of my script and Unity error.
using UnityEngine; using System.Collections; [RequireComponent (typeof(CharacterController))] public class FirstPersonController : MonoBehaviour { public float movementspeed = 5.0f; public float sidespeed = 3.0f; public float UpDownRange = 60.0f; public float mousespeed = 2.0f; public float jumpSpeed = 2.0f; float verticalRotation = 0; float VerticalVelocity = 0; CharacterController characterController; // Use this for initialization void Start () { Screen.lockCursor = true; CharacterController characterController = GetComponent <CharacterController> (); Debug.Log(characterController); } // Update is called once per frame void Update () { //rotation float rotLeftRight = Input.GetAxis ("Mouse X") * mousespeed; transform.Rotate (0, rotLeftRight, 0); verticalRotation -= Input.GetAxis ("Mouse Y") * mousespeed; verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange); Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0); //movement float forwardSpeed = Input.GetAxis("Vertical") * movementspeed; float sideSpeed = Input.GetAxis("Horizontal") * sidespeed; VerticalVelocity += Physics.gravity.y * Time.deltaTime; if( characterController.isGrounded Input.GetButtonDown("Jump") ) { VerticalVelocity = jumpSpeed; } Vector3 speed = new Vector3 ( sideSpeed, VerticalVelocity, forwardSpeed ); speed = transform.rotation * speed; characterController.Move( speed * Time.deltaTime ); } } Maybe you will find something here? .
I didnt get any parsing error but CharacterController characterController was being defined twice so I just removed one and the code below works Code (csharp): using UnityEngine; using System.Collections; [RequireComponent (typeof(CharacterController))] public class FirstPersonController : MonoBehaviour { public float movementspeed = 5.0f; public float sidespeed = 3.0f; public float UpDownRange = 60.0f; public float mousespeed = 2.0f; public float jumpSpeed = 2.0f; float verticalRotation = 0; float VerticalVelocity = 0; CharacterController characterController; // Use this for initialization void Start () { Screen.lockCursor = true; characterController = GetComponent <CharacterController> (); Debug.Log(characterController); } // Update is called once per frame void Update () { //rotation float rotLeftRight = Input.GetAxis ("Mouse X") * mousespeed; transform.Rotate (0, rotLeftRight, 0); verticalRotation -= Input.GetAxis ("Mouse Y") * mousespeed; verticalRotation = Mathf.Clamp (verticalRotation, -UpDownRange, UpDownRange); Camera.main.transform.localRotation = Quaternion.Euler (verticalRotation, 0, 0); //movement float forwardSpeed = Input.GetAxis("Vertical") * movementspeed; float sideSpeed = Input.GetAxis("Horizontal") * sidespeed; VerticalVelocity += Physics.gravity.y * Time.deltaTime; if(characterController.isGrounded Input.GetButtonDown("Jump")) { VerticalVelocity = jumpSpeed; } Vector3 speed = new Vector3 ( sideSpeed, VerticalVelocity, forwardSpeed ); speed = transform.rotation * speed; characterController.Move( speed * Time.deltaTime ); }