Unity初心者です
https://rightcode.co.jp/blog/information-technology/unity-wheelcollider-create-simple-racing-game
このサイトをマネしながら車を動かす練習をしていましたがCarMove.csを作成してコンポーネントしてもこんな表示が出てきませんhttps://rightcode.co.jp/wp-content/uploads/2020/10/unity-wheelcollider-create-05.png
> CarMove.csを作成して
と書いてありますが、スクリーンショットは CarMove"2" になっています。質問内容が矛盾しますがどちらが正しいですか?
スクリーンショットの撮影している範囲が十分ではありませんが、プロジェクトにはコンパイル エラーは出ていませんか?それは Unity Editor の一番下に出てきます。またそのスクリーンショットで映っている範囲の下はどのようになっているのでしょうか?設定するための項目が出てきているのかいないのか、その範囲のスクリーンショットではわかりません。
そして、CarMove2には何が書かれていますか?
CarMove2には
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CarMove : MonoBehaviour
{
public List<AxleInfo> axleInfos;
public float maxMotorTorque;
public float maxSteeringAngle;
public void FixedUpdate()
{
float motor = maxMotorTorque * Input.GetAxis("Vertical");
float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
foreach (AxleInfo axleInfo in axleInfos)
{
if (axleInfo.steering)
{
axleInfo.leftWheel.steerAngle = steering;
axleInfo.rightWheel.steerAngle = steering;
}
if (axleInfo.motor)
{
axleInfo.leftWheel.motorTorque = motor;
axleInfo.rightWheel.motorTorque = motor;
}
}
}
}
[System.Serializable]
public class AxleInfo
{
public WheelCollider leftWheel;
public WheelCollider rightWheel;
public bool motor;
public bool steering;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CarMove : MonoBehaviour
{
public List<AxleInfo> axleInfos;
public float maxMotorTorque;
public float maxSteeringAngle;
public void FixedUpdate()
{
float motor = maxMotorTorque * Input.GetAxis("Vertical");
float steering = maxSteeringAngle * Input.GetAxis("Horizontal");
foreach (AxleInfo axleInfo in axleInfos)
{
if (axleInfo.steering)
{
axleInfo.leftWheel.steerAngle = steering;
axleInfo.rightWheel.steerAngle = steering;
}
if (axleInfo.motor)
{
axleInfo.leftWheel.motorTorque = motor;
axleInfo.rightWheel.motorTorque = motor;
}
}
}
}
[System.Serializable]
public class AxleInfo
{
public WheelCollider leftWheel;
public WheelCollider rightWheel;
public bool motor;
public bool steering;
}
と書いていまして、
Assets\CarMove2.cs(79,1): error CS1529: A using clause must precede all other elements defined in the namespace except extern alias declarations
というエラーが出ています
CarMove2 をプロジェクトから削除して、参照先のブログの通りに CarMove という名前で作ればよいでしょう。
変わりませんでした
コードが、ここにペーストした通りに「同じものが2回繰り返している、そして間に数字の羅列が挟まっている」状態なら、それはコピペのやり方を間違っているので、画面に表示されている状態になるようにしてください。
ブログのコードが表示されている部分の右上の "Copy" というボタンを押せばコピーできる状態になります。
たしかに同じものが2回繰り返されていました
結果画像のようになりました。
これであっているでしょうか?
質問を更新しましたのでお願いします。
実行するとこんなエラーが出ていました。
WheelCollider requires an attached Rigidbody to function.