我试图通过youtube视频https://www.youtube.com/watch?v=xTTBbXYH9BA&t=585s制作无尽的游戏。在视频中,代码正常运行。但是在我的Visual Studio中,它说“Vector3不包含带有四个参数的构造函数”。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
private bool ismovingright = false;
[SerializeField]
float speed = 4f;
void Start ()
{
rb = this.GetComponent<Rigidbody>();
}
private Rigidbody rb;
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
ChangeBoolean();
ChangeDirection();
}
}
private void ChangeBoolean()
{
ismovingright = !ismovingright;
}
private void ChangeDirection()
{
if (ismovingright)
{
rb.velocity = new Vector3(speed, 0f, 0f,);
}
else
{
rb.velocity = new Vector3(0f, 0f, speed);
}
}
}
答案 0 :(得分:1)
你有一个拼写错误,0f后还有一个额外的逗号
if (ismovingright)
{
rb.velocity = new Vector3(speed, 0f, 0f,);
}else