c#与unity的代码问题

img


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

public class SphereContral : MonoBehaviour
{
    private Rigidbody rb;

   void Start()
    {
        rb = GetComponent<Rigidbody>();
    }
    void FixedUpdate()
    {
        float horinput=Input.GetAxis("Horizontal");
        float verinput=Input.GetAxis("Vertical");

        Vector3 movement = new Vector3(GetAxisZ, 0, deltaX);

        rb.AddForce(movement*10);
    }
}

unity3d中一个球被上下左右键控制移动的代码,想问一下问题出在哪,该怎么改正,这个报错是unity报的,vs显示这个没有错误

Vector3 movement = new Vector3(GetAxisZ, 0, deltaX)修改为Vector3 movement = new Vector3(horinput, 0, verinput)试试。
实在不行,你试试我这个代码

    public class PlayerMove : MonoBehaviour {
    public float PlayerSpeed = 1.0f;
    public bool TrueJump;
    public GameObject rb;//注意,需要将所控制的物体在Inspector页面上拖入该脚本组件下的rb游戏对象
    // Use this for initialization
    void Start () {
        TrueJump = true;
        
    }

    // Update is called once per frame
    void Update()
    {
        rb.AddComponent<Rigidbody>();//添加刚体组件
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        transform.Translate(new Vector3(h, 0, v) * Time.deltaTime * PlayerSpeed);
        //以下为控制跳跃的代码(在空中不得再次跳跃)
        if (Input.GetKeyDown(KeyCode.Space) && TrueJump == true)
        {
            transform.Translate(0, 2, 0);
            TrueJump = false;
        }
    }
    void OnCollisionStay()
    {
        TrueJump = true;
    }
}

你贴出来的代码和报错不是同一个文件。

1.你问题是啥?是unity有报错吗?把unity报错粘贴出来
2.你移动代码就这些吗?定义的horinput、verinput没有用到啊?你的getaxisZ,deltaX在哪里定义的?