【发布时间】:2020-01-31 02:25:16
【问题描述】:
当我尝试运行此程序时,我是统一的新手,它给了我错误 无法将类型 '(float xpos, int, int)' 隐式转换为 'UnityEngine.Vector3'
这是我的代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField]
private float _speed = 3.5f;
// Start is called before the first frame update
void Start()
{
transform.position = new Vector3(0, 0, 0);
}
// Update is called once per frame
void Update()
{
//variables
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
float xpos = transform.position.x ;
Vector3 direction = new Vector3(horizontalInput, verticalInput, 0);
transform.Translate(direction * _speed * Time.deltaTime);
if (transform.position.y >= 0)
{
transform.position = (xpos, 0, 0);
}
else if (transform.position.y <= -3.8f)
{
transform.position = new Vector3(xpos, -3.8f, 0);
}
}
}
【问题讨论】:
-
仔细查看所有其他你做类似事情的行,你会发现不同之处。
-
@RetiredNinja 对不起,我看不到。
-
transform.position = new Vector3(0, 0, 0);与transform.position = (xpos, 0, 0); -
非常感谢!我把头发拉出来就是为了这样一个简单的修复!
标签: c# unity3d compiler-errors game-engine