Placeholder chracter is moving

This commit is contained in:
2018-04-21 12:02:32 +10:00
parent 4ba501dfed
commit 4207fc4661
23 changed files with 1283 additions and 2 deletions
+55
View File
@@ -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);
}
}
+13
View File
@@ -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: