- Home /
C# Very Basic Character Controller Script
So my problem is I'm getting the error
Assets/Custom Scripts/controller.cs(23,26): error CS1525: Unexpected symbol `cc'
I tried replacing CC with charactercontroller which I found in the documentation but I still got the same problem. Please Help!
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(CharacterController))]
public class controller : MonoBehaviour {
public float MoveSpeed;
CharacterController cc;
void Start ()
{
cc = GetComponent<CharacterController>();
}
void Update ()
{
//moves the vector forward 1 point so original point is //vector 0,0,0 then changes to vector 0,0,1
Vector3 foward = Input.GetAxis("Vertical")*transform.TransformDirection(Vector3.forward)*MoveSpeed
cc.Move(forward* Time.deltaTime);
cc.SimpleMove(Physics.gravity);
}
}
Answer by Graham-Dunnett · May 24, 2015 at 07:46 PM
Is line 22 missing a semi colon?
Vector3 foward = Input.GetAxis("Vertical")transform.TransformDirection(Vector3.forward)$$anonymous$$oveSpeed
";"
Vector3 foward = Input.GetAxis("Vertical")*transform.TransformDirection(Vector3.forward)*$$anonymous$$oveSpeed ; <-- !! ";"
Edit : Converted your comment to an answer, and my answer to a comment under it since you actually posted before I did. This site is bugging, your comment wasn't even visible on my screen until a few moments ago.
Omg can't belive I didn't notice that could have saved me a head ache Thanks!
Answer by Heitor Segadas · May 26, 2015 at 06:29 AM
Tente isto (try it) mas lembre-se de substituir os nomes das classes pela sua:
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody rb;
void Start ()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * 10);
}
}
Your answer
Follow this Question
Related Questions
How to get our character controller script to make our player move? 1 Answer
3D Character Controller slowing down the higher the slope angle (both up and down) 1 Answer
Making a bubble level (not a game but work tool) 1 Answer
Need helping getting a character controller to jump 1 Answer
[C#] Movement Direction Change 2 Answers