Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerC : MonoBehaviour {
- private float movementSpeed = 8.0f;
- private float walkSpeed = 4.5f;
- private float gravity = 5.0f;
- private float gforce;
- private Vector3 direction;
- CharacterController player;
- Animator anim;
- // Use this for initialization
- void Start () {
- player = GetComponent<CharacterController>();
- anim = GetComponent<Animator>();
- }
- // Update is called once per frame
- void Update () {
- gforce = Time.deltaTime * gravity;
- player.Move(Vector3.down * gforce);
- movementSpeed = 8.0f;
- if (player.isGrounded)
- {
- gforce = 0;
- Vector3 agg = new Vector3();
- if (Input.GetButton("W"))
- {
- agg += transform.forward;
- }
- else
- {
- if (Input.GetButton("S")) {
- agg -= transform.forward;
- movementSpeed = walkSpeed;
- }
- }
- if (Input.GetButton("A")) agg -= transform.right;
- if (Input.GetButton("D")) agg += transform.right;
- agg = agg.normalized;
- transform.position += agg * Time.smoothDeltaTime * movementSpeed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement