@System.NonSerialized var isMoving = false; @System.NonSerialized var collisionFlags : CollisionFlags; @System.NonSerialized var velocity : Vector3; @System.NonSerialized var inAirVelocity = Vector3.zero; @System.NonSerialized var hangTime = 0.0; var sneakControllerHeight : float = 0.95; var sneakControllerCenter : Vector3 = Vector3(0,0.5,0);}class PlatformerControllerJumping{ var enabled = true; var height = 1.0; var extraHeight = 4.1; @System.NonSerialized var repeatTime = 0.05; @System.NonSerialized var timeout = 0.15; @System.NonSerialized var jumping = false; @System.NonSerialized var reachedApex = false; @System.NonSerialized var lastButtonTime = -10.0; @System.NonSerialized var lastTime = -1.0; @System.NonSerialized var lastStartHeight = 0.0;} Sobre nossas classes:Ao salvar seu script, voce pode ver que todas as variaveis expostas das classes aparecem de maneira elegante e organizada no Inspector.Nao existem mais tantas duvidas sobre a funcionalidade das animacoes, entao nao ha necessidade de informacao redundante. O que estas irao fazer e simplesmente pegar as informacoes que o player insere atraves de valores seja em um gamepad ou teclado e implementar a interatividade, mandando mensagens nos momentos certos para que as animacoes sigam a logica definida pela interatividade proposta. Neste momento em diante a questao de jogabilidade vai se tornando cada vez mais presente e voce se ver por horas e horas aprimorando a movimentacao e Gameplay de seu personagem. Em uma situacao assim com tantas variaveis co-relacionadas e sempre bom utilizar uma classe para tornar o trabalho menos doloroso.Com nossas classes definidas, vamos em frente em trabalhar com o conteudo oferecido por elas:? 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 function Awake(){ movement.direction = transform.TransformDirection(Vector3.forward); controller = GetComponent(CharacterController); Spawn();}function FixedUpdate(){ transform.position.z = 0;}function Update(){ if (isDying != true) { if (Input.GetButtonDown ("Jump") && canControl) { jump.lastButtonTime = Time.time; } UpdateSmoothedMovementDirection(); ApplyGravity(); ApplyJumping(); lastPosition = transform.position; var currentMovementOffset = movement.direction * movement.speed + Vector3 (0, movement.verticalSpeed, 0) + movement.inAirVelocity; currentMovementOffset *= Time.deltaTime; movement.collisionFlags = controller.Move (currentMovementOffset); movement.velocity = (transform.position - lastPosition) / Time.deltaTime; if (movement.direction.sqrMagnitude > 0.01) transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation (movement.direction), Time.deltaTime * movement.rotationSmoothing); if (controller.isGrounded) { movement.inAirVelocity = Vector3.zero; if (jump.jumping) { jump.jumping = false; SendMessage ("DidLand", SendMessageOptions.DontRequireReceiver); var jumpMoveDirection = movement.direction * movement.speed + movement.inAirVelocity; if (jumpMoveDirection.sqrMagnitude > 0.01) movement.direction = jumpMoveDirection.normalized; } } UpdateEffects (); if (isSneaking == true) { if (controller.height != movement.sneakControllerHeight) {controller.height = movement.sneakControllerHeight;} if (controller.center != movement.sneakControllerCenter) {controller.center = movement.sneakControllerCenter;} } else { if (headsUp == false) { if (controller.height != 1.85) {controller.height = 1.85;} if (controller.center != Vector3(0,0.98,0)) {controller.center = Vector3(0,0.98,0);} } } var hit : RaycastHit; var floorRect = transform.TransformDirection(Vector3(0,-1,0)); if (Physics.Raycast(transform.position,floorRect,hit)) { if (hit.distance >= 6.5) { isFalling = true; } } if (isFalling == true) { if (Input.GetButton("Jump")) { if (jump.enabled == true) { animation.Stop("Fall"); animation.CrossFade("Stay Jumping"); isFalling = false; } } } }}function UpdateSmoothedMovementDirection(){ var h = Input.GetAxisRaw ("Horizontal"); if (!canControl) h = 0.0; movement.isMoving = Mathf.Abs (h) > 0.1; if (movement.isMoving) movement.direction = Vector3 (h, 0, 0); if (controller.isGrounded) { var curSmooth = movement.speedSmoothing * Time.deltaTime; var targetSpeed = Mathf.Min (Mathf.Abs(h), 1.0); if (isSneaking == false && headsUp == false) { if (Input.GetButton ("Action A") && canControl) { targetSpeed *= movement.runSpeed; } else { targetSpeed *= movement.walkSpeed; } } else { targetSpeed *= movement.walkSpeed; } movement.speed = Mathf.Lerp (movement.speed, targetSpeed, curSmooth); movement.hangTime = 0.0;