Skip to content

Instantly share code, notes, and snippets.

@lynical-dev
Created May 3, 2020 07:23
Show Gist options
  • Save lynical-dev/d3c6556745132b8fdf5fab9998334019 to your computer and use it in GitHub Desktop.
Save lynical-dev/d3c6556745132b8fdf5fab9998334019 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controller : MonoBehaviour
{
public float Speed;
Animator anim;
private bool isMoving = false;
public void Start()
{
anim = GetComponent<Animator>();
if(anim != null)
{
anim.SetFloat("Speed_f", 0.0f);
anim.SetBool("Static_b", true);
}
}
public void Update()
{
this.PlayerMovement();
}
public void PlayerMovement()
{
float hor = Input.GetAxis("Horizontal");
float ver = Input.GetAxis("Vertical");
Vector3 playerMovement = new Vector3(hor, 0f, ver).normalized * Speed * Time.deltaTime;
transform.Translate(playerMovement, Space.Self);
if (this.anim != null)
{
if ((Mathf.Abs(ver) > 0.0f) || (Mathf.Abs(hor) > 0.0f))
{
if (!this.isMoving)
{
this.isMoving = true;
this.anim.SetFloat("Speed_f", 0.4f);
}
else if (this.isMoving)
{
this.isMoving = false;
this.anim.SetFloat("Speed_f", 0.0f);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment