Skip to content

Instantly share code, notes, and snippets.

@toshikaz55
Created December 12, 2013 12:57
Show Gist options
  • Save toshikaz55/7927544 to your computer and use it in GitHub Desktop.
Save toshikaz55/7927544 to your computer and use it in GitHub Desktop.
UnityでキャラクターをHorizontal方向に動かすC#スクリプト
using UnityEngine;
using System.Collections;
public class motionCtrl : MonoBehaviour {
Animator animator;
CharacterController character;
// Use this for initialization
void Start () {
character = GetComponent<CharacterController>();
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
// Get Key Input
float v = Input.GetAxis("Vertical");
float h = Input.GetAxis ("Horizontal");
bool isJump = Input.GetKey(KeyCode.Space);
animator.SetFloat("Speed", h);
if (isJump) {
animator.SetBool("Jump", true);
} else {
animator.SetBool("Jump", false);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment