dポイントプレゼントキャンペーン実施中!

Unityの教科書通りにやったのですが、
if(Inpit.GetButtonDown(0))の、0に赤線が引かれて、

引数1:は'int'から'string'へ変換することはできません。

エラーとなります。

どこを直せば良いのでしょうか…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CarController : MonoBehaviour
{
float speed = 0;

// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
if(Input.GetButtonDown(0)) //マウスがクリックされたら
{
this.speed = 0.2f; //初速度を設定
}

transform.Translate(this.speed, 0, 0); //移動
this.speed *= 0.98f; //減速

}
}

A 回答 (2件)

No.1です。



もしかしてこっちかな?
https://docs.unity3d.com/ja/2017.4/ScriptReferen …

.GetButtonDown(~

ではなく

.GetMouseButtonDown(0)

とか?
    • good
    • 0
この回答へのお礼

ありがとうございます。
教科書通りにやったつもりが、Mouseを入れ忘れてました…
本当にありがとうございます。

お礼日時:2019/11/04 18:32

Unity触ったことないですがぐぐってみたら、


https://qiita.com/RyotaMurohoshi/items/688fe33f4 …

0 と言う数値ではなくButton名:文字列を入れなきゃいけないのでは?
仮に 0 のButtonなら ("0") になるのかも??????わかんないけど。
    • good
    • 1

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!