(NullReferenceException:对象引用未设置为对象的实例),但是即使我没有C#脚本,也会弹出此错误

时间:2019-07-13 13:46:06

标签: c# unity3d nullreferenceexception

我正在用C#编写一个播放器控制器以实现统一,并且不断收到nullreferencexception。它在第24行引发错误。

我尝试了在没有body2d的情况下工作,当然,它是行不通的,并且我尝试了针对已建议问题的其他解决方案。

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

public class PlayerController : MonoBehaviour
{
public float speed;
public float jumpForce;
private float moveInput;

private Rigidbody2D rb;

private bool facingRight = true;

void start()
{
    rb = GetComponent<Rigidbody2D>();

}
void FixedUpdate()
{
    moveInput = Input.GetAxis("horizontal");
    Debug.Log(moveInput);
    rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

}
void Flip()
{
    facingRight = !facingRight;
    Vector3 Scaler = transform.localScale;
    Scaler.x *= -1;
    transform.localScale = Scaler;
}
}

0 个答案:

没有答案