# button gone

**URL:** https://discussions.unity.com/t/button-gone/925896
**Category:** 2D
**Tags:** 2D, Question
**Created:** [August 9, 2023, 6:05pm UTC](https://discussions.unity.com/t/button-gone/925896 "2023-08-09T18:05:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mytravelzoid](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@mytravelzoid](https://discussions.unity.com/u/mytravelzoid)
#### Post date: [August 9, 2023, 6:05pm UTC](https://discussions.unity.com/t/button-gone/925896/1 "2023-08-09T18:05:54Z")

</div>

when i play my buttons are gone but before this never happened the button did not disappear i have 3 scripts in one of the scripts all my debug statements did not execute

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpawnWood : MonoBehaviour
{
    public GameObject Wood12345678910;
    public Vector2 Spawn;
    public AudioSource audioSource;

    private GameObject currentWood; // Reference to the currently spawned wood
    private bool isDragging = false;

    private void Start ()
    {
        audioSource = GetComponent<AudioSource>();
    }

    private void Update ()
    {
        if (transform.position.y > -53f)
        {
            Destroy(gameObject);
        }

        if (isDragging && currentWood != null)
        {
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mousePosition.z = 0f; // Set z position to 0 to avoid depth issues
            currentWood.transform.position = mousePosition;

            float rotation = -Input.GetAxis("Mouse X") * 10f; // Calculate rotation based on mouse movement
            currentWood.transform.Rotate(Vector3.forward, rotation);
        }
    }

    public void WoodSpawn ()
    {
        if (currentWood == null)
        {
            currentWood = Instantiate(Wood12345678910, Spawn, Quaternion.identity);
            Rigidbody2D woodRigidbody = currentWood.AddComponent<Rigidbody2D>();

            if (woodRigidbody != null)
            {
                woodRigidbody.gravityScale = 0.0f; // Set initial gravity scale to 0
            }
        }
        else
        {
            Destroy(currentWood);
            currentWood = null;
        }

        if (!audioSource.isPlaying)
        {
            audioSource.Play();
        }
        else
        {
            audioSource.Stop();
        }
    }

    public void StartDragging ()
    {
        isDragging = true;

        if (currentWood != null)
        {
            Rigidbody2D woodRigidbody = currentWood.GetComponent<Rigidbody2D>();
            if (woodRigidbody != null)
            {
                woodRigidbody.gravityScale = 1.0f; // Enable gravity when dragging starts
            }
        }
    }

    public void StopDragging ()
    {
        isDragging = false;
        if (currentWood != null)
        {
            Rigidbody2D woodRigidbody = currentWood.GetComponent<Rigidbody2D>();
            if (woodRigidbody != null)
            {
                woodRigidbody.gravityScale = 0.0f; // Disable gravity when dragging stops
            }
        }
    }
}

```

second script

```csharp
using UnityEngine;

public class Rotate : MonoBehaviour
{
    public float rotationSpeed = 1f;

    // Update is called once per frame
    void Update()
    {
        float rotationAmount = rotationSpeed * Time.deltaTime;
        transform.Rotate(0, 0, rotationAmount);
    }
}

```

third

```csharp
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragAndDrop : MonoBehaviour
{
    private bool isDragging = false;
    private Vector3 offset;

    private void OnMouseDown ()
    {
        Debug.Log("Is dragging is true");
        if (Input.touchCount > 0) return; // Ignore touch input for now
        offset = transform.position - GetMouseWorldPos();
        isDragging = true;
    }

    private void OnMouseUp ()
    {
        isDragging = false;
        Debug.Log("Is dragging is false");
    }

    private void Update ()
    {
        if (isDragging)
        {
            Debug.Log("Dragging");
            Vector3 mouseWorldPos = GetMouseWorldPos();
            transform.position = new Vector3(mouseWorldPos.x + offset.x, mouseWorldPos.y + offset.y, transform.position.z);
        }
    }

    private Vector3 GetMouseWorldPos ()
    {
        Debug.Log("Mouse Stored");
        Vector3 mousePos = Input.mousePosition;
        mousePos.z = -Camera.main.transform.position.z;
        return Camera.main.ScreenToWorldPoint(mousePos);
    }
}

```

---

<div class="post-metadata">

### Author: ![Kurt-Dekker](https://dub1.discourse-cdn.com/unity/user_avatar/discussions.unity.com/kurt-dekker/32/101578_2.png) [@Kurt-Dekker](https://discussions.unity.com/u/Kurt-Dekker)
#### Post date: [August 10, 2023, 4:15am UTC](https://discussions.unity.com/t/button-gone/925896/2 "2023-08-10T04:15:31Z")

</div>

> [@mytravelzoid](#):
>
> all my debug statements did not execute

Find out why.

Time to start debugging! Here is how you can begin your exciting new debugging adventures:

You must find a way to get the information you need in order to reason about what the problem is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

What is often happening in these cases is one of the following:

- the code you think is executing is not actually executing at all
- the code is executing far EARLIER or LATER than you think
- the code is executing far LESS OFTEN than you think
- the code is executing far MORE OFTEN than you think
- the code is executing on another GameObject than you think it is
- you’re getting an error or warning and you haven’t noticed it in the console window

To help gain more insight into your problem, I recommend liberally sprinkling `Debug.Log()` statements through your code to display information in realtime.

Doing this should help you answer these types of questions:

- is this code even running? which parts are running? how often does it run? what order does it run in?
- what are the names of the GameObjects or Components involved?
- what are the values of the variables involved? Are they initialized? Are the values reasonable?
- are you meeting ALL the requirements to receive callbacks such as triggers / colliders (review the documentation)

Knowing this information will help you reason about the behavior you are seeing.

You can also supply a second argument to Debug.Log() and when you click the message, it will highlight the object in scene, such as `Debug.Log("Problem!",this);`

If your problem would benefit from in-scene or in-game visualization, Debug.DrawRay() or Debug.DrawLine() can help you visualize things like rays (used in raycasting) or distances.

You can also call Debug.Break() to pause the Editor when certain interesting pieces of code run, and then study the scene manually, looking for all the parts, where they are, what scripts are on them, etc.

You can also call GameObject.CreatePrimitive() to emplace debug-marker-ish objects in the scene at runtime.

You could also just display various important quantities in UI Text elements to watch them change as you play the game.

Visit Google for how to see console output from builds. If you are running a mobile device you can also view the console output. Google for how on your particular mobile target, such as this answer for iOS: [https://discussions.unity.com/t/700551](https://discussions.unity.com/t/700551) or this answer for Android: [https://discussions.unity.com/t/699654](https://discussions.unity.com/t/699654)

If you are working in VR, it might be useful to make your on onscreen log output, or integrate one from the asset store, so you can see what is happening as you operate your software.

Another useful approach is to temporarily strip out everything besides what is necessary to prove your issue. This can simplify and isolate compounding effects of other items in your scene or prefab.

If your problem is with OnCollision-type functions, print the name of what is passed in!

Here’s an example of putting in a laser-focused Debug.Log() and how that can save you a TON of time wallowing around speculating what might be going wrong:

[https://discussions.unity.com/t/839300/3](https://discussions.unity.com/t/839300/3)

**“When in doubt, print it out!™” - Kurt Dekker (and many others)**

Note: the `print()` function is an alias for Debug.Log() provided by the MonoBehaviour class.
