【问题标题】:Operator '*' cannot be applied to operands of type 'Vector3' and 'Vector3'运算符“*”不能应用于“Vector3”和“Vector3”类型的操作数
【发布时间】:2020-07-06 19:09:13
【问题描述】:

我在 youtube 上观看教程以使我的统一角色移动,但我被困在移动中。我检查了 cmets 看看是否有人有同样的问题我没有看到任何人有同样的问题,但我收到了这个错误:

Assets\PlayerMov.cs(15,24):错误 CS0019:运算符“*”不能应用于“Vector3”和“Vector3”类型的操作数

这是我的代码:

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

public class PlayerMov : MonoBehaviour
{
    public CharacterController controller;

    public float speed = 12f;
  
    void Update()
    {
        float x = Input.GetAxis("Horizontal");
        float z = Input.GetAxis("Vertical");

        Vector3 move =(transform.right * x * transform.forward * z);

        controller.Move(move * speed * Time.deltaTime);
    }
}

【问题讨论】:

  • 那行中间的* 可能是+ 的拼写错误。
  • Vector3 move = transform.right * x + transform.forward * z;

标签: c#


【解决方案1】:

Unity 仅支持 multiplication of Vector3 by a number。但是你可以add 两个向量或subtract 一个来自另一个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-02-10
    • 1970-01-01
    • 2021-07-27
    • 2020-10-19
    • 2014-05-27
    • 2015-01-25
    • 2011-12-31
    相关资源
    最近更新 更多