Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. using UnityEngine;
  2.  using System.Collections;
  3.  using System;
  4.  
  5. public class Character : MonoBehaviour
  6.  
  7. {
  8.     //max speed of character
  9.     public float maxSpeed =5.0f;
  10.     public float facingAngleAdjustment = -90f;
  11.  
  12.  
  13.     private Animator animator;
  14.     //cached version of our physics rigid body.
  15.     private Rigidbody2D cachedRigidBody2D;
  16.     private Transform cachedTransform;
  17.  
  18.     void Awake()
  19.     {
  20.     }
  21.  
  22.     private void Start()
  23.     {
  24.         this.animator = this.GetComponent<Animator>();
  25.         this.cachedTransform = this.GetComponent<Transform>();
  26.         this.cachedRigidBody2D = this.GetComponent<Rigidbody2D>();
  27.     }
  28.  
  29.     public void Move(Vector2 movement)
  30.     {
  31.         //move the rigid body, which is part of the physics system
  32.         //This ensures smooth movement.
  33.         this.cachedRigidBody2D.velocity = new Vector2(movement.x * maxSpeed, movement.y * maxSpeed);
  34.  
  35.         float speed = Mathf.Abs(movement.x) + Mathf.Abs(movement.y);
  36.  
  37.         this.animator.SetFloat("Speed", speed);
  38.  
  39.         float angle = Mathf.Atan2(movement.y, movement.x) * Mathf.Rad2Deg + facingAngleAdjustment;
  40.  
  41.         //don't rotate if we don't need to.
  42.         if (speed > 0.0f)
  43.         {
  44.             //rotate by angle around the z axis.
  45.             this.cachedTransform.rotation = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
  46.         }
  47.     }
  48.  
  49.     private delegate void Death();
  50.  
  51.     public void SetDeathFunction(Death d)
  52.     {
  53.  
  54.     }
  55.  
  56.     public void AdjustHealth(int i)
  57.     {
  58.     }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement