ボールを動かそう
![2cf97397 ddb7 4c84 aad8 2130bf1973e4](https://codegenius.org/uploads/slide/image/1821/2cf97397-ddb7-4c84-aad8-2130bf1973e4.jpeg)
![91b97668 de80 4253 a807 5a5ed304d1d4](https://codegenius.org/uploads/slide/image/1822/91b97668-de80-4253-a807-5a5ed304d1d4.jpeg)
ボールを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
// 変数の定義(まずはこの用語を頭にインプットしましょう。)
// ★↓これを記載する
public float moveSpeed;
private Rigidbody rb;
void Start()
{
// ★↓これを記載する
rb = GetComponent<Rigidbody>();
}
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);
}
}
![942e1133 25bc 4700 8138 860aef5646cf](https://codegenius.org/uploads/slide/image/1823/942e1133-25bc-4700-8138-860aef5646cf.jpeg)
![Fb16164a 5a0b 4721 b6eb 365b32c8e7be](https://codegenius.org/uploads/slide/image/1824/fb16164a-5a0b-4721-b6eb-365b32c8e7be.jpeg)
![35e79344 30b7 4df0 9806 4fa68e012ee7](https://codegenius.org/uploads/slide/image/1825/35e79344-30b7-4df0-9806-4fa68e012ee7.jpeg)
![4de581d5 7e34 49dc a2c1 c17fc4c2e210](https://codegenius.org/uploads/slide/image/1826/4de581d5-7e34-49dc-a2c1-c17fc4c2e210.jpeg)
![7101c91a cc08 4c57 990f a3f1d46a501f](https://codegenius.org/uploads/slide/image/1827/7101c91a-cc08-4c57-990f-a3f1d46a501f.jpeg)
【2018版】BallGame(全25回)
他のコースを見る![2cf97397 ddb7 4c84 aad8 2130bf1973e4](https://codegenius.org/uploads/slide/image/1821/2cf97397-ddb7-4c84-aad8-2130bf1973e4.jpeg)
![91b97668 de80 4253 a807 5a5ed304d1d4](https://codegenius.org/uploads/slide/image/1822/91b97668-de80-4253-a807-5a5ed304d1d4.jpeg)
ボールを動かす
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Ball : MonoBehaviour
{
// 変数の定義(まずはこの用語を頭にインプットしましょう。)
// ★↓これを記載する
public float moveSpeed;
private Rigidbody rb;
void Start()
{
// ★↓これを記載する
rb = GetComponent<Rigidbody>();
}
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);
}
}
![942e1133 25bc 4700 8138 860aef5646cf](https://codegenius.org/uploads/slide/image/1823/942e1133-25bc-4700-8138-860aef5646cf.jpeg)
![Fb16164a 5a0b 4721 b6eb 365b32c8e7be](https://codegenius.org/uploads/slide/image/1824/fb16164a-5a0b-4721-b6eb-365b32c8e7be.jpeg)
![35e79344 30b7 4df0 9806 4fa68e012ee7](https://codegenius.org/uploads/slide/image/1825/35e79344-30b7-4df0-9806-4fa68e012ee7.jpeg)
![4de581d5 7e34 49dc a2c1 c17fc4c2e210](https://codegenius.org/uploads/slide/image/1826/4de581d5-7e34-49dc-a2c1-c17fc4c2e210.jpeg)
![7101c91a cc08 4c57 990f a3f1d46a501f](https://codegenius.org/uploads/slide/image/1827/7101c91a-cc08-4c57-990f-a3f1d46a501f.jpeg)
ボールを動かそう