There is a Prefab already existing in Unity Project. When I rename the prefab and try to use it in c# script, I get an error.
Assets\Scripts\GameControl.cs(9,12): error CS0246: The type or namespace name ‘time’ could not be found (are you missing a using directive or an assembly reference?)
Most likely prefab has nothing to do with it, but there’s a typo in the script. It is hard to tell what ort of typo, because you’ve not posted any code.
It is possible, however, t hat it is something like “time.deltaTime” instead of “Time.deltaTime”.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameControl : MonoBehaviour
{
public static readonly int totalStick = 54;
public static readonly int stickPerLayer = 3;
public time woodstick;
public static int stickNumberVariable=1;
public static int collisionVariable=0;
void Start()
{
stickNumberVariable=1;
collisionVariable=0;
Time.timeScale = 2;
for(int h = 0; h < totalStick/stickPerLayer; h++)
{
for(int i = 0; i < stickPerLayer; i++)
{
time locStick;
locStick = Instantiate(woodstick);
locStick.stickNumber=stickNumberVariable;
stickNumberVariable++;
if (h % 2 == 0)
{
locStick.transform.position += new Vector3((time.x * i), (time.y * h), 0);
}
else
{
locStick.transform.position += new Vector3((time.x * i), (time.y * h), -time.z);
locStick.transform.RotateAround(transform.position, new Vector3(0, -1, 0), 90);
}
locStick.SetOriginalPosition();
}
}
collisionVariable++;
}
public void Restart()
{
stickNumberVariable=1;
collisionVariable=0;
var sticks = FindObjectsOfType<WoodStick>();
foreach (WoodStick ws in sticks)
{
ws.RevertPosition();
}
}
}
What is it even supposed to do? If you’re trying to instantiate an object from prefab reference, it should be public GameObject woodstick;, or, seeing that you have a WoodStick behavior somewhere, public WoodStick woodstick;
Funny Thing. If I rename a Prefab object (say ‘WoodStick’ to ‘WoodStick1’). And then again rename it (to ‘WoodStick’ from ‘WoodStick1’), the game stops working!
When I try to instantiate an prefab, I get the following error:
ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.Instantiate[T] (T original) (at :0)
GameControl.Start () (at Assets/Scripts/GameControl.cs:28)