Placeholder chracter is moving
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class Player : MonoBehaviour {
|
||||
Animator animator;
|
||||
Rigidbody2D rigidBody;
|
||||
|
||||
float speed;
|
||||
Vector2 deltaForce;
|
||||
Vector2 lastDirection;
|
||||
bool isShooting;
|
||||
|
||||
void Awake() {
|
||||
animator = GetComponent<Animator> ();
|
||||
rigidBody = GetComponent<Rigidbody2D> ();
|
||||
|
||||
speed = 1f;
|
||||
}
|
||||
|
||||
void Update() {
|
||||
HandleInput ();
|
||||
Move ();
|
||||
SendAnimationInfo ();
|
||||
}
|
||||
|
||||
void HandleInput() {
|
||||
//determine the input from the player
|
||||
float horizontal = Input.GetAxis ("Horizontal");
|
||||
float vertical = Input.GetAxis ("Vertical");
|
||||
|
||||
deltaForce = new Vector2 (horizontal, vertical);
|
||||
|
||||
//calculate last direction
|
||||
if (deltaForce != Vector2.zero) {
|
||||
lastDirection = rigidBody.velocity;
|
||||
}
|
||||
|
||||
//calculate if shooting
|
||||
isShooting = Input.GetButton ("Attack");
|
||||
}
|
||||
|
||||
void Move() {
|
||||
//determine how to move the character
|
||||
rigidBody.velocity = Vector2.zero;
|
||||
Vector2 impulse = deltaForce.normalized * speed;
|
||||
rigidBody.AddForce (impulse, ForceMode2D.Impulse);
|
||||
}
|
||||
|
||||
void SendAnimationInfo() {
|
||||
animator.SetFloat ("xSpeed", lastDirection.x);
|
||||
animator.SetFloat ("ySpeed", lastDirection.y);
|
||||
animator.SetBool ("isShooting", isShooting);
|
||||
}
|
||||
}
|
||||
Generated
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c9a7a743ce869904ca255dc7e2ecd693
|
||||
timeCreated: 1524272726
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user