And please give a better description than “Won’t Work”. That tells us nothing. What behavior did you expect would happen, and what actually happens instead?
Like Starmanta said, your question is awful vague, but here’s a few things that might be causing you issues:
You’re using forwardspeed and horizontalspeed before assigning them a value, which means you’re starting with Forward= (0,0,0) and Right = (0,0,0). And that’s assuming Unity is smart enough to assign them a 0 because you didn’t give it anything to work with yet. I don’t know if Unity does that, or if it just leaves a random value in that memory space.
You also take the input only in Start(), which means you take the input when the object this script is on is created, and then never again. I’d recommend adding an Input() function to get your inputs, and then calling it in Update().
Last, but not least; You’re calling movement functions in Update(). While this in theory works, Update() is called on every frame of the game, which can be inconsistent. To keep your physics from going wonky on you, call them in FixedUpdate().
Here’s some sample of what I’m talking about:
//only called when this Object is created.
void Start()
{
forwardspeed=0;
horizontalspeed=0;
CharacterController = GetComponent<CharacterController>();
}
//Get our current inputs
void Input()
{
forwardspeed=Input.GetAxis("Vertical");
horizontalspeed=Input.GetAxis("Horizontal");
//I'm not sure why you have this middle-step, but I guess it makes your SimpleMove commands more legible...
///Consider combining both these into a single Vector3(horizontalspeed,0,forwardspeed), that you then pass to the CharacterController.
Forward=new Vector3(0,0,forwardspeed);
Right=new Vector3(horizontalspeed,0,0);
}
//Happens every frame of the game. Put visuals-only stuff in here (UI, Camera movement, etc)
void Update()
{
Input();
}
//Happens at regular intervals; put your Physics stuff in here.
void FixedUpdate()
{
CharacterController.SimpleMove (Forward);
CharacterController.SimpleMove (Right);
}