-
Notifications
You must be signed in to change notification settings - Fork 1
/
CC.cs
35 lines (28 loc) · 988 Bytes
/
CC.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using UnityEngine;
using System.Collections;
public class CC : MonoBehaviour {
CharacterController controller;
int speed = 100;
public float jumpSpeed = 800.0F;
public float gravity = 2.0F;
private Vector3 moveDirection = Vector3.zero;
// Use this for initialization
void Start () {
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
//controller.SimpleMove(new Vector3(speed * Input.GetAxis("Horizontal"), 0));
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetButton("Jump"))
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}