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
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
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
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);
}
}