Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Move(bool left,bool right, bool crouch, bool jump)
- {
- if (right) {
- switch (forwardDirection) {
- case 1:
- m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
- break;
- case 2:
- m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
- break;
- case 3:
- m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
- break;
- case 4:
- m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
- break;
- }
- } else if (left) {
- switch (forwardDirection) {
- case 1:
- m_Rigidbody.velocity = new Vector3 (-12f, 0, 0f);
- break;
- case 2:
- m_Rigidbody.velocity = new Vector3 (0f, 0, 12f);
- break;
- case 3:
- m_Rigidbody.velocity = new Vector3 (0f, 0, -12f);
- break;
- case 4:
- m_Rigidbody.velocity = new Vector3 (12f, 0, 0f);
- break;
- }
- } else {
- switch (forwardDirection) {
- case 1:
- m_Rigidbody.velocity = new Vector3 (0f, 0f, 10f);
- break;
- case 2:
- m_Rigidbody.velocity = new Vector3 (10f, 0f, 0f);
- break;
- case 3:
- m_Rigidbody.velocity = new Vector3 (-10f, 0f, 0f);
- break;
- case 4:
- m_Rigidbody.velocity = new Vector3 (0f, 0f, -10f);
- break;
- }
- }
- if (crouch && m_Animator.GetCurrentAnimatorStateInfo (0).IsName ("Run")) {
- m_Crouching=true;
- }else{
- m_Crouching=false;
- }
- CheckGroundStatus ();
- if (!turn) {
- UpdateAnimator (jump);
- } else {
- if(right)
- {
- turn=false;
- Vector3 temp=transform.rotation.eulerAngles;
- if(temp.y<269f){
- temp.y=temp.y+90f; }
- else {
- temp.y=0;
- }
- transform.eulerAngles = temp;
- switch (forwardDirection) {
- case 1:
- forwardDirection=2;
- break;
- case 2:
- forwardDirection=4;
- break;
- case 3:
- forwardDirection=1;
- break;
- case 4:
- forwardDirection=3;
- break;
- }
- }else if(left){
- turn=false;
- Vector3 temp=transform.rotation.eulerAngles;
- if(temp.y>-269f){
- temp.y=temp.y-90f; }
- else {
- temp.y=0;
- }
- transform.eulerAngles = temp;
- switch (forwardDirection) {
- case 1:
- forwardDirection=3;
- break;
- case 2:
- forwardDirection=1;
- break;
- case 3:
- forwardDirection=4;
- break;
- case 4:
- forwardDirection=2;
- break;
- }
- }
- }
- right = false;
- left = false;
- }
- void UpdateAnimator(bool jump)
- {
- if (jump) {
- m_Animator.SetBool ("Jump", true);
- } else {
- m_Animator.SetBool ("Jump", false);
- }
- if (m_Crouching) {
- m_Animator.SetBool ("Crouch", true);
- count = 0;
- }
- else {
- count +=1;
- if(count>100)
- m_Animator.SetBool ("Crouch", false);
- }
- }
- public void OnAnimatorMove()
- {
- if (m_IsGrounded && Time.deltaTime > 0)
- {
- Vector3 v = (m_Animator.deltaPosition * m_MoveSpeedMultiplier) / Time.deltaTime;
- // we preserve the existing y part of the current velocity.
- v.y = m_Rigidbody.velocity.y;
- m_Rigidbody.velocity = v;
- }
- }
- public void setTurn(bool t){
- turn = t;
- }
- void Start () {
- Vector3 angles = transform.eulerAngles;
- x = angles.x;
- y = angles.y;
- }
- void LateUpdate () {
- if(!target)
- return;
- y = target.eulerAngles.y;
- // ROTATE CAMERA:
- Quaternion rotation = Quaternion.Euler (x, y, 0);
- transform.rotation = rotation;
- // POSITION CAMERA:
- transform.position = target.position - (rotation * Vector3.forward * distance + new Vector3(0,-targetHeight,0));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement