ボールを動かそう
![9de32fab 93bc 490f 8e25 e80b9814a981](https://codegenius.org/uploads/slide/image/3533/9de32fab-93bc-490f-8e25-e80b9814a981.jpeg)
![Aec6374d 5945 4c41 93e7 593340cb8cf2](https://codegenius.org/uploads/slide/image/3534/aec6374d-5945-4c41-93e7-593340cb8cf2.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);
}
}
![7fd926ec 02df 4e41 ba4f 3e50fa962f43](https://codegenius.org/uploads/slide/image/3535/7fd926ec-02df-4e41-ba4f-3e50fa962f43.jpeg)
![7cc77c88 3377 4e8c b779 0eead700472b](https://codegenius.org/uploads/slide/image/3536/7cc77c88-3377-4e8c-b779-0eead700472b.jpeg)
![C7ba9152 3549 4d42 9597 5382b84b9974](https://codegenius.org/uploads/slide/image/3537/c7ba9152-3549-4d42-9597-5382b84b9974.jpeg)
![31188ae2 a52e 4bb7 95c0 b4d63c34fcae](https://codegenius.org/uploads/slide/image/3538/31188ae2-a52e-4bb7-95c0-b4d63c34fcae.jpeg)
![83fde7b5 0fba 4feb bc03 ad04dc72e771](https://codegenius.org/uploads/slide/image/3539/83fde7b5-0fba-4feb-bc03-ad04dc72e771.jpeg)
【2019版】BallGame(全27回)
他のコースを見る![9de32fab 93bc 490f 8e25 e80b9814a981](https://codegenius.org/uploads/slide/image/3533/9de32fab-93bc-490f-8e25-e80b9814a981.jpeg)
![Aec6374d 5945 4c41 93e7 593340cb8cf2](https://codegenius.org/uploads/slide/image/3534/aec6374d-5945-4c41-93e7-593340cb8cf2.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);
}
}
![7fd926ec 02df 4e41 ba4f 3e50fa962f43](https://codegenius.org/uploads/slide/image/3535/7fd926ec-02df-4e41-ba4f-3e50fa962f43.jpeg)
![7cc77c88 3377 4e8c b779 0eead700472b](https://codegenius.org/uploads/slide/image/3536/7cc77c88-3377-4e8c-b779-0eead700472b.jpeg)
![C7ba9152 3549 4d42 9597 5382b84b9974](https://codegenius.org/uploads/slide/image/3537/c7ba9152-3549-4d42-9597-5382b84b9974.jpeg)
![31188ae2 a52e 4bb7 95c0 b4d63c34fcae](https://codegenius.org/uploads/slide/image/3538/31188ae2-a52e-4bb7-95c0-b4d63c34fcae.jpeg)
![83fde7b5 0fba 4feb bc03 ad04dc72e771](https://codegenius.org/uploads/slide/image/3539/83fde7b5-0fba-4feb-bc03-ad04dc72e771.jpeg)
ボールを動かそう