Problem was solved on my own.
[SOLVED]I'm trying to destroy a button. YOU MAY WANT TO CHECK THIS THREAD IF DESTROY OBJECT IS NOT WORKING FOR NO GOOD REASON. [SOLVED]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroyObject : MonoBehaviour
{
public void DestroyThisObject()
{
Debug.Log ("Calling");
Destroy (gameObject);
}
}
This doesn't work! I've tried this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroyObject : MonoBehaviour
{
private HUDMenu headsUpMenu;
void Awake ()
{
headsUpMenu = FindObjectOfType<HUDMenu> ();
}
public void Update()
{
if(headsUpMenu.communicationsOn)
{
Debug.Log ("Calling");
Destroy (gameObject);
}
}
}
I've tried this!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroyObject : MonoBehaviour
{
private HUDMenu headsUpMenu;
private int progress = 0;
void Awake ()
{
headsUpMenu = FindObjectOfType<HUDMenu> ();
}
public void DestroyThisObject()
{
if(headsUpMenu.communicationsOn)
{
if(progress < 1)
{
progress += 1;
Debug.Log ("Calling all Destroyers");
Destroy (gameObject);
}
}
}
}
I've tried this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SelfDestroyObject : MonoBehaviour
{
private HUDMenu headsUpMenu;
private int progress = 0;
void Awake ()
{
headsUpMenu = FindObjectOfType<HUDMenu> ();
}
public void Update()
{
if(headsUpMenu.communicationsOn)
{
if(progress < 1)
{
progress += 1;
Debug.Log ("Calling all Destroyers");
Destroy (gameObject);
}
}
}
}
This last one worked for awhile until it just didn't! I wasn't even working on code! I was working on graphics, and it just magically stopped working!
Nothing works! It doesn't even call the function! I've been putting it in the onclick function in my inspector! You can't say I'm not doing that! It will not destroy the object! I just want to make the effing b to go away!!!
Oh, almost forgot to say! Nope! It's not calling the debug log!
SEE ALL THESE PROBLEMS I'M HAVING! TURNS OUT IT WASN'T THE CODE. MY INPUT MANAGER WAS CORRUPTED. GUYS, IF YOU'VE GOT CODE THAT SHOULD BE WORKING BUT ISN'T (AND EVERYONE IS TELLING YOU THAT IT LOOKS GOOD) CHECK YOUR PROJECT SETTINGS. THERE'S A GOOD CHANCE SOMETHING IS CORRUPTED. I ACTUALLY GOT THE SOLUTION TO THIS WHEN ALL INPUT SUDDENLY BROKE AND MY CHARACTER CONTROLLER STOPPED WORKING. I SEARCHED AND WAS TOLD MY INPUT MANAGER WAS PROBABLY CORRUPTED AND TO SWITCH IT WITH ONE FROM A NEW PROJECT. I DID AND NOT ONLY DID IT WORK, BUT IT FIXED ALL OF THE CODING PROBLEMS I'D BEEN HAVING FOR THE DURATION OF THE WHOLE PROJECT.