Unity报错:The variable ... has not been assigned.

Unity报错:The variable prg of Rg02 has not been assigned.

The variable prg of Rg02 has not been assigned.

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

public class Rg02 : MonoBehaviour {
    public Rigidbody prg;

    // Use this for initialization
    void Start () {
		
	}
	
	// Update is called once per frame
	void Update () {
        
        prg.position = prg.transform.position + Vector3.forward * Time.deltaTime;
    }
}

报错:

UnassignedReferenceException: The variable prg of Rg02 has not been assigned.
You probably need to assign the prg variable of the Rg02 script in the inspector.
Rg02.Update () (at Assets/Rg02.cs:17)

原因:没有给物体添加刚体组件

把物体拉到里面进行设置就可以了

在unity中出现

UnassignedReferenceException: The variable target of Moving has not been assigned.
You probably need to assign the target variable of the Moving script in the inspector.

Moving.Update () (at Assets/_Tutorial/Moving.cs:13)


发现如上图中 traget 为none  把物体拉到里面进行设置也就可以了
 

猜你喜欢

转载自blog.csdn.net/milli236/article/details/83110979