Question by
B1tCr8ator · Jun 13, 2019 at 12:24 PM ·
instantiatewarning
The problem with the Instantiate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BreakBlock : MonoBehaviour {
public GameObject WoodBlockDrop;
private float Distance;
private string Name;
private RaycastHit hit;
private Ray ray;
void Update () {
ray = Camera.main.ScreenPointToRay (new Vector3(Screen.width/2, Screen.height/2, 0));
if (Physics.Raycast(ray,out hit) && hit.collider.gameObject.tag == "Interaction") {
Distance = Vector3.Distance (hit.collider.gameObject.transform.position, gameObject.transform.position);
Name = hit.collider.gameObject.name;
if (Distance < 7f) {
if (Input.GetMouseButtonDown (0)) {
if (Name == "WoodBlock") {
Instantiate (WoodBlockDrop, hit.collider.gameObject.transform);
if (WoodBlockDrop)
Destroy (hit.collider.gameObject);
}
}
}
}
}
}
It gives this: The referenced script on this Behaviour (Game Object 'WoodBlockDrop') is missing! UnityEngine.Object:Instantiate(GameObject, Transform) BreakBlock:Update() (at Assets/Character/Scripts/BreakBlock.cs:22)
And WoodBlockDrop does not appear. How to fix?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612203133im_/https://answers.unity.com/themes/thub/images/avi.jpg)