I’m sorry, but my brain sometimes just takes English statements and translates them literally. And forms a really mean immediate response. I can’t help it… it just happens. So with that said…
Because you wrote it that way.
. . .
Anyways… use code tags:
//it's using, and it's System, not Using and system
Using system.collections;
Using UnityEngine;
//all these public's should be lower-case
Public class Movement : MonoBehaviour
{
Public float Speed = 6;
Public float Jumpspeed=8;
Public float Gravity = 20
CharacterController controller;
Void Awake () {
//'controller' is already defined, don't redefine it
Charactercontroller controller = GetComponent <CharacterController>();
//you're accessing GameObject.AddComponent as a static method. It should be this.AddComponent.
//Also, why are you adding a CharacterController after you've just called GetComponent? GetComponent would have returned null if it wasn't there...
//Also why are you using the generic accessor for get, but the string accessor for add?
GameObject.AddComponent("CharacterController");
}
//update is called once per frame
Void Update ()
{
//moveDirection is not defined as a variable, what is it?
//also Collision flags flags? It should be CollisionFlags flags =
Collission flags flags = controller.Move (movedirection*time.deltaTime);
//isGrounded is undefined as a variable, what is it?
isGrounded =( flags & CollisionFlags.Collidebelow) != 0;
//still undefined
If (isGrounded){
//undefined! - also it's Input, not input
Movedirection = new Vector3(input.GetAxis("horizontal"), 0, Input.GetAxis ("vertical"));
//you changed case, of an undefined variable. Define it, and keep the correct casing.
moveDirection = transform.TransformDirection(moveDirection);
//needs a ; at the end
moveDirection *= speed
If (input.GetButton ("jump"))
{
moveDirection.y = JumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime //no ; at end
//from here, I don't even know what's up. You left out the rest of the method, and also... you already moved the CharacterController... what is this code even for?
So I rewrote it to be what I presume it should be… I don’t know, since your Update method is just basically gibberish. This is the best of my ability at figuring out what you meant to be doing:
using System.Collections;
using UnityEngine;
public class Movement : MonoBehaviour
{
public float Speed = 6;
public float Jumpspeed=8;
public float Gravity = 20
private CharacterController controller;
void Awake() {
controller = this.GetComponent<CharacterController>();
if(controller == null)
controller = this.AddComponent<CharacterController>();
}
void Update()
{
Vector3 moveDirection = new Vector3(Input.GetAxis("horizontal"), 0, Input.GetAxis ("vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
if (controller.isGrounded && Input.GetButton ("jump"))
{
moveDirection.y = JumpSpeed;
}
else
{
moveDirection.y -= Gravity * Time.deltaTime;
}
controller.Move(movedirection*time.deltaTime);
}
}