c#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4 5public class animator : MonoBehaviour { 6 7 public Animator anim; 8 public Rigidbody rbody; 9 10 private float inputH; 11 private float inputV; 12 13 // Use this for initialization 14 void Start () { 15 16 anim = GetComponent<Animator>(); 17 rbody = GetComponent<Rigidbody>(); 18 19 } 20 21 // Update is called once per frame 22 void Update () { 23 if (Input.GetKeyDown ("1")) { 24 anim.Play ("WAIT01", -1, 0f); 25 } 26 if (Input.GetKeyDown ("2")) { 27 anim.Play ("WAIT02", -1, 0f); 28 } 29 if (Input.GetKeyDown ("3")) { 30 anim.Play ("WAIT03", -1, 0f); 31 } 32 if (Input.GetKeyDown ("4")) { 33 anim.Play ("WAIT04", -1, 0f); 34 } 35 if (Input.GetMouseButtonDown (0)) { 36 int n = Random.Range (0, 2); 37 38 if (n == 0) { 39 anim.Play ("DAMAGED00", -1, 0f); 40 } else { 41 anim.Play ("DAMAGED01", -1, 0f); 42 } 43 } 44 inputH = Input.GetAxis ("Horizontal"); 45 inputV = Input.GetAxis ("Vertical"); 46 47 anim.SetFloat ("inputH", inputH); 48 anim.SetFloat ("inputV", inputV); 49 50 float moveX = inputH * 20f * Time.deltaTime; 51 float moveZ = inputV * 50f * Time.deltaTime; 52 53 rbody.velocity = new Vector3 (moveX, 0f, moveZ); 54 } 55} 56```youtubeのUnity 5 Tutorial - Animation Controlという動画とまったく同じように作っているつもりなのですが、歩くアニメーションはうまくいくのに実際に歩かせることができません。ボタンを押すとアニメーションのみが動きます。動かすコードをtranslate.Transformにすると動きますがrigidbodyで動かしたいです。エラーは出てません。原因がrigidbodyとanimatonの併用であることはわかっています。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/01/21 14:39
2017/01/21 15:08
2017/01/22 01:54
2017/01/22 06:12
2017/01/23 08:01