ボールを動かそう
![D9c81c00 868c 4ec2 b7ba fa382dbc0893](https://codegenius.org/uploads/slide/image/5638/d9c81c00-868c-4ec2-b7ba-fa382dbc0893.jpeg)
![E1fa197e 83ee 4f76 93c4 78dfd42618e1](https://codegenius.org/uploads/slide/image/5639/e1fa197e-83ee-4f76-93c4-78dfd42618e1.jpeg)
ボールを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
// 『変数』の定義(まずは変数という単語を頭にインプットしましょう。)
// ★↓これを記載する
public float moveSpeed;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
// ★↓これを記載する
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// ★↓これを記載する
// HorizontalとVerticalのスペルに注意(ポイント)
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveH, 0, moveV);
rb.AddForce(movement * moveSpeed);
}
}
![0abb6c8e dae8 4a54 8522 60cb8bf8eb82](https://codegenius.org/uploads/slide/image/5640/0abb6c8e-dae8-4a54-8522-60cb8bf8eb82.jpeg)
![B28f8291 5e2d 4e41 a13b 5f82aa2644bb](https://codegenius.org/uploads/slide/image/5641/b28f8291-5e2d-4e41-a13b-5f82aa2644bb.jpeg)
![55a84984 2349 4c15 ac0d c35538a66e8d](https://codegenius.org/uploads/slide/image/5642/55a84984-2349-4c15-ac0d-c35538a66e8d.jpeg)
![658551a0 c0e6 447e ab83 705399b73118](https://codegenius.org/uploads/slide/image/5643/658551a0-c0e6-447e-ab83-705399b73118.jpeg)
![2059559a 488f 45d4 8a71 0573e1a81676](https://codegenius.org/uploads/slide/image/5644/2059559a-488f-45d4-8a71-0573e1a81676.jpeg)
【2020版】BallGame(全27回)
他のコースを見る![D9c81c00 868c 4ec2 b7ba fa382dbc0893](https://codegenius.org/uploads/slide/image/5638/d9c81c00-868c-4ec2-b7ba-fa382dbc0893.jpeg)
![E1fa197e 83ee 4f76 93c4 78dfd42618e1](https://codegenius.org/uploads/slide/image/5639/e1fa197e-83ee-4f76-93c4-78dfd42618e1.jpeg)
ボールを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
// 『変数』の定義(まずは変数という単語を頭にインプットしましょう。)
// ★↓これを記載する
public float moveSpeed;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
// ★↓これを記載する
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// ★↓これを記載する
// HorizontalとVerticalのスペルに注意(ポイント)
float moveH = Input.GetAxis("Horizontal");
float moveV = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveH, 0, moveV);
rb.AddForce(movement * moveSpeed);
}
}
![0abb6c8e dae8 4a54 8522 60cb8bf8eb82](https://codegenius.org/uploads/slide/image/5640/0abb6c8e-dae8-4a54-8522-60cb8bf8eb82.jpeg)
![B28f8291 5e2d 4e41 a13b 5f82aa2644bb](https://codegenius.org/uploads/slide/image/5641/b28f8291-5e2d-4e41-a13b-5f82aa2644bb.jpeg)
![55a84984 2349 4c15 ac0d c35538a66e8d](https://codegenius.org/uploads/slide/image/5642/55a84984-2349-4c15-ac0d-c35538a66e8d.jpeg)
![658551a0 c0e6 447e ab83 705399b73118](https://codegenius.org/uploads/slide/image/5643/658551a0-c0e6-447e-ab83-705399b73118.jpeg)
![2059559a 488f 45d4 8a71 0573e1a81676](https://codegenius.org/uploads/slide/image/5644/2059559a-488f-45d4-8a71-0573e1a81676.jpeg)
ボールを動かそう