Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System;
- public class Character : MonoBehaviour
- {
- //max speed of character
- public float maxSpeed =5.0f;
- public float facingAngleAdjustment = -90f;
- private Animator animator;
- //cached version of our physics rigid body.
- private Rigidbody2D cachedRigidBody2D;
- private Transform cachedTransform;
- void Awake()
- {
- }
- private void Start()
- {
- this.animator = this.GetComponent<Animator>();
- this.cachedTransform = this.GetComponent<Transform>();
- this.cachedRigidBody2D = this.GetComponent<Rigidbody2D>();
- }
- public void Move(Vector2 movement)
- {
- //move the rigid body, which is part of the physics system
- //This ensures smooth movement.
- this.cachedRigidBody2D.velocity = new Vector2(movement.x * maxSpeed, movement.y * maxSpeed);
- float speed = Mathf.Abs(movement.x) + Mathf.Abs(movement.y);
- this.animator.SetFloat("Speed", speed);
- float angle = Mathf.Atan2(movement.y, movement.x) * Mathf.Rad2Deg + facingAngleAdjustment;
- //don't rotate if we don't need to.
- if (speed > 0.0f)
- {
- //rotate by angle around the z axis.
- this.cachedTransform.rotation = Quaternion.AngleAxis(angle, new Vector3(0, 0, 1));
- }
- }
- private delegate void Death();
- public void SetDeathFunction(Death d)
- {
- }
- public void AdjustHealth(int i)
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement