【问题标题】:Unity error CS0201: Only assignment, call, increment, decrement, await, and new object expressions can be used as a statementunity error CS0201: 只有赋值、调用、递增、递减、等待和新对象表达式可以作为语句使用
【发布时间】:2020-04-08 07:14:08
【问题描述】:

我刚开始编程,正在学习如何统一制作游戏的教程 所以我做了一切就像视频说的但我仍然收到这个错误 谁能解释一下我做错了什么?

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

public class Player : MonoBehaviour
{

    public float playerSpeed = 500;
    public float directionalSpeed = 20;

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

    // Update is called once per frame
    void Update() {
#if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER
        .transform.position.y, gameObject.transform.position.z), directionalSpeed * Time.deltaTime);
#endif
        float moveHorizontal = Input.GetAxis("Horizontal");
        transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(Mathf.Clamp(gameObject.transform.position.x + moveHorizontal, -2.5f, 2.5f), gameObject
        GetComponent<Rigidbody>().velocity = Vector3.forward * playerSpeed * Time.deltaTime;
        //Mobile Controls
        Vector2 touch = Camera.main.ScreenToWorldPoint(Input.mousePosition + new Vector3(0, 0, 10f));
        if (Input.touchCount > 0)
        {    
           transform.position + new Vector3(touch.x, transform.position.y, transform.position.z);            
        }     
    }
}

【问题讨论】:

  • 请注意,这个transform.position + ... 也绝对没有任何作用......它会返回一个新的Vector3,但结果没有存储在任何地方......您可能想将其设为+= 或仅= 而不是实际移动对象?

标签: c# unity3d


【解决方案1】:

实际上你会得到的代码是:

void Update() {
.transform.position.y, ...), directionalSpeed * ...);
}

这是无效的。这就是为什么。

【讨论】:

    猜你喜欢
    • 2020-11-24
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 2016-06-27
    • 2013-09-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    相关资源
    最近更新 更多