Deleting objects at specific position
Hey, I'm trying to make my objects delete themselves after they reach a certain value on an axis, however when I try to attach my transform to the script in the Unity Editor, it doesn't let me. Below is the script that I'm using in case that is the problem.
using UnityEngine;
using System.Collections;
public class WaterDestroy : MonoBehaviour
{
public Transform deletePos;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (transform.position.y <= deletePos.position.y)
{
Destroy (this.gameObject);
}
}
}
Please help, this is for an assessment.
When you say that it "won't let you" what does it do ins$$anonymous$$d? Does the variable not appear in the inspector for you to drop your object into? Or does it appear, but when you try to drop the object in, it won't allow it? Something else?
Answer by Edy · Feb 24, 2016 at 05:11 PM
Ensure that the script name is WaterDestroy.cs exactly (case sensitive).
In Unity components the name of the script must match the name of the MonoBehaviour-derived class.