Added a basic animation to player along with a movement change and some minor bug fixes

This commit is contained in:
Gregory Campbell
2020-07-12 11:56:45 -04:00
parent 7f5e6fe48f
commit 4e53e69050
17 changed files with 352 additions and 3 deletions
+12 -3
View File
@@ -18,11 +18,14 @@ public class PlayerScript : MonoBehaviour
private float myTime = 0.0f;
private GameObject reloaded;
private Rigidbody2D rb;
private Vector2 movement;
private Animator animator;
private AudioSource audioSource;
void Awake()
{
animator = GetComponent<Animator>();
audioSource = GetComponent<AudioSource>();
rb = GetComponent<Rigidbody2D>();
reloaded = GameObject.Find("Reloaded");
@@ -30,6 +33,13 @@ public class PlayerScript : MonoBehaviour
void Update()
{
movement.x = Input.GetAxis("Horizontal");
movement.y = Input.GetAxis("Vertical");
animator.SetFloat("Horizontal", movement.x);
animator.SetFloat("Vertical", movement.y);
animator.SetFloat("Speed", movement.sqrMagnitude);
reloaded.SetActive(false);
myTime += Time.deltaTime;
@@ -42,7 +52,7 @@ public class PlayerScript : MonoBehaviour
if(Input.GetButton("Fire1") && myTime > nextFire)
{
GunFire();
nextFire = Random.Range(0.0f, 2.0f);
nextFire = Random.Range(0.25f, 2.0f);
myTime = 0.0f;
}
@@ -56,8 +66,7 @@ public class PlayerScript : MonoBehaviour
void FixedUpdate()
{
rb.velocity =
new Vector2(Input.GetAxis("Horizontal") * speed, Input.GetAxis("Vertical") * speed);
rb.MovePosition(rb.position + movement * speed * Time.fixedDeltaTime);
}