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 Player : MonoBehaviour {
- //Animation du perso//
- Animation animations;
- //Vitesse de déplacement//
- public float walkSpeed;
- public float runSpeed;
- public float turnSpeed;
- //Inputs//
- public string inputFront;
- public string inputBack;
- public string inputRight;
- public string inputLeft;
- public Vector3 jumpSpeed;
- CapsuleCollider playerCollider;
- /// ///////////Fin déclaration variable//////
- //début void start//
- void Start () {
- animations = gameObject.GetComponent<Animation>();
- playerCollider = gameObject.GetComponent<CapsuleCollider>();
- //fin void start//
- }
- bool IsGrounded()
- {
- return Physics.CheckCapsule(playerCollider.bounds.center, new Vector3(playerCollider.bounds.center.x, playerCollider.bounds.min.y - 0.1f, playerCollider.bounds.center.z), 0.11f);
- }
- //début void update//
- void Update () {
- //avancer//
- if (Input.GetKey(inputFront) && !Input.GetKey(KeyCode.LeftShift))
- {
- transform.Translate(0, 0, walkSpeed * Time.deltaTime);
- animations.Play("walk");
- //reculer//
- }
- //si on sprint//
- if (Input.GetKey(inputFront) && Input.GetKey(KeyCode.LeftShift))
- {
- transform.Translate(0, 0, runSpeed * Time.deltaTime);
- animations.Play("run");
- }
- if (Input.GetKey(inputBack))
- {
- transform.Translate(0, 0, -(walkSpeed /2) * Time.deltaTime);
- animations.Play("walk");
- }
- //rotation a gauche//
- if (Input.GetKey(inputLeft))
- {
- transform.Rotate(0, -turnSpeed * Time.deltaTime, 0);
- }
- //rotation à droite//
- if (Input.GetKey(inputRight))
- {
- transform.Rotate(0, turnSpeed * Time.deltaTime, 0);
- }
- //idle//
- if (!Input.GetKey(inputFront) && !Input.GetKey(inputBack))
- {
- animations.Play ("idle");
- }
- //Si on saute//
- if(Input.GetKeyDown(KeyCode.Space) && IsGrounded())
- {
- //préparation du saut (nécessaire en c#)
- Vector3 v = gameObject.GetComponent<Rigidbody>().velocity;
- v.y = jumpSpeed.y;
- //Saut//
- gameObject.GetComponent<Rigidbody>().velocity = jumpSpeed;
- }
- //fin update//
- }
- //fin script//
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement