Skip to content

Instantly share code, notes, and snippets.

@bibinba
Last active October 27, 2017 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bibinba/8bb0d4206e1893bc7f29dc80037f0a17 to your computer and use it in GitHub Desktop.
Save bibinba/8bb0d4206e1893bc7f29dc80037f0a17 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class button_idou : MonoBehaviour {
public GameObject player;
bool forwardmove;
bool backmove;
bool rightmove;
bool leftmove;
bool run;
private Vector3 prev;
private Animator animator;
void Start(){
prev = player.transform.position;
animator = player.GetComponent<Animator>();
}
void Update(){
////体の向き
var diff = player.transform.position - prev;
if (diff.magnitude > 0.01) {
player.transform.rotation = Quaternion.LookRotation(diff);
}
prev = player.transform.position;
///移動
if(forwardmove == true){
player.transform.position += new Vector3(0,0,1 * Time.deltaTime);
animator.SetBool("is_running", true);
}
if(backmove == true){
player.transform.position += new Vector3(0,0,-1 * Time.deltaTime);
animator.SetBool("is_running", true);
}
if(rightmove == true){
player.transform.position += new Vector3(1 * Time.deltaTime,0,0);
animator.SetBool("is_running", true);
}
if(leftmove == true){
player.transform.position += new Vector3(-1 * Time.deltaTime,0,0);
animator.SetBool("is_running", true);
}
if (forwardmove == false && backmove == false && leftmove == false && rightmove == false) {
animator.SetBool ("is_running", false);
}
}
////ここをEventTriggerに付ける
public void forwardButtonDown(){
forwardmove = true;
}
public void forwardButtonUp(){
forwardmove = false;
}
public void backButtonDown(){
backmove = true;
}
public void backButtonUp(){
backmove = false;
}
public void rightButtonDown(){
rightmove = true;
}
public void rightButtonUp(){
rightmove = false;
}
public void leftButtonDown(){
leftmove = true;
}
public void leftButtonUp(){
leftmove = false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment