ボールを動かそう


ボールを動かす
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);
}
}





【2021版】BallGame(全31回)
他のコースを見る

ボールを動かす
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);
}
}





ボールを動かそう