Home>

I'm a beginner using c # in unity.
I want to make a wall that flows from right to left every few seconds.

Error message
UnassignedReferenceException: The variable graywall of RepetitionWall has not been assigned.
You probably need to assign the graywall variable of the RepetitionWall script in the inspector.
UnityEngine.Object.Instantiate [T] (T original) (at C: /buildslave/unity/build/Runtime/Export/Scripting/UnityEngineObject.bindings.cs:266)
RepetitionWall.Update () (at Assets/script/RepetitionWall.cs: 23)

Corresponding source code
c #
Source code

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

public class RepetitionWall: MonoBehaviour
{
public float intervalMin, intervalMax;

public float instanceTime;

public GameObject graywall;
// Start is called before the first frame update
void Start ()
{

}

// Update is called once per frame
void Update ()
{
if (instanceTime<= 0)
{
GameObject newwall = Instantiate (graywall);
newwall.transform.position = transform.position;
instanceTime = Random.Range (intervalMin, intervalMax);
}
else else
{
instanceTime-= Time.deltaTime;
}

}

}

What I tried

I didn't know what to try.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.