ボールを動かそう
![160b8031 ece1 47d9 b70b 146319a62b15](https://codegenius.org/uploads/slide/image/9485/160b8031-ece1-47d9-b70b-146319a62b15.jpeg)
![Dc34e7bf 77ae 4c50 b5a0 1362e477a3d6](https://codegenius.org/uploads/slide/image/9486/dc34e7bf-77ae-4c50-b5a0-1362e477a3d6.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);
}
}
![129f34b4 aeee 4940 9d26 cd1af7a3690d](https://codegenius.org/uploads/slide/image/9487/129f34b4-aeee-4940-9d26-cd1af7a3690d.jpeg)
![02dc6b8b 088e 461c 86e0 5887ce732814](https://codegenius.org/uploads/slide/image/9488/02dc6b8b-088e-461c-86e0-5887ce732814.jpeg)
![B6949c97 4354 47cc abfc 3e05c53c2935](https://codegenius.org/uploads/slide/image/9489/b6949c97-4354-47cc-abfc-3e05c53c2935.jpeg)
![7fa250a7 a27f 4661 8fd2 3ad90f8a5967](https://codegenius.org/uploads/slide/image/9490/7fa250a7-a27f-4661-8fd2-3ad90f8a5967.jpeg)
![2b5a7607 2e05 4be3 a1d1 0b4719ce6f20](https://codegenius.org/uploads/slide/image/9491/2b5a7607-2e05-4be3-a1d1-0b4719ce6f20.jpeg)
【2022版】BallGame(全27回)
他のコースを見る![160b8031 ece1 47d9 b70b 146319a62b15](https://codegenius.org/uploads/slide/image/9485/160b8031-ece1-47d9-b70b-146319a62b15.jpeg)
![Dc34e7bf 77ae 4c50 b5a0 1362e477a3d6](https://codegenius.org/uploads/slide/image/9486/dc34e7bf-77ae-4c50-b5a0-1362e477a3d6.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);
}
}
![129f34b4 aeee 4940 9d26 cd1af7a3690d](https://codegenius.org/uploads/slide/image/9487/129f34b4-aeee-4940-9d26-cd1af7a3690d.jpeg)
![02dc6b8b 088e 461c 86e0 5887ce732814](https://codegenius.org/uploads/slide/image/9488/02dc6b8b-088e-461c-86e0-5887ce732814.jpeg)
![B6949c97 4354 47cc abfc 3e05c53c2935](https://codegenius.org/uploads/slide/image/9489/b6949c97-4354-47cc-abfc-3e05c53c2935.jpeg)
![7fa250a7 a27f 4661 8fd2 3ad90f8a5967](https://codegenius.org/uploads/slide/image/9490/7fa250a7-a27f-4661-8fd2-3ad90f8a5967.jpeg)
![2b5a7607 2e05 4be3 a1d1 0b4719ce6f20](https://codegenius.org/uploads/slide/image/9491/2b5a7607-2e05-4be3-a1d1-0b4719ce6f20.jpeg)
ボールを動かそう