1. 程式人生 > >Unity報錯:The variable ... has not been assigned.

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  把物體拉到裡面進行設定也就可以了