emem> butonanimations.cs
Код: Выделить всё
using UnityEngine;
public class ButtonAnimations : MonoBehaviour
{
private Rigidbody2D rb;
private static Vector2 gravityDirection; // Gravity yönü
private static bool gravitySet = false; // Gravity sadece bir kere ayarlansın
private string WALL_TAG = "Wall";
private float startingSpeed = 200f;
private int gravityScale = 10;
private float gravity = 9.81f;
private float mass = 5f;
void Start()
{
Debug.Log("Start() ÇALIŞTI - Buton tekrar oluşturuldu");
rb = GetComponent();
rb.bodyType = RigidbodyType2D.Dynamic;
rb.gravityScale = gravityScale;
rb.interpolation = RigidbodyInterpolation2D.Interpolate;
rb.drag = 0.05f;
rb.angularDrag = 0.05f;
rb.mass = mass;
if (!gravitySet)
{
SetRandomGravityDirection();
gravitySet = true;
}
// Global gravity yönünü değiştiriyoruz
Physics2D.gravity = gravityDirection * gravity;
// Başlangıçta hız veriyoruz
rb.velocity = gravityDirection * startingSpeed;
Debug.Log("Başlangıç hızı verildi: " + rb.velocity);
Debug.Log("Yerçekimi yönü: " + gravityDirection);
}
void SetRandomGravityDirection()
{
int randomDir = Random.Range(0, 3);
switch (randomDir)
{
case 0: gravityDirection = Vector2.down; break;
case 1: gravityDirection = Vector2.left; break;
case 2: gravityDirection = Vector2.right; break;
}
Debug.Log("Yeni Gravity Yönü: " + gravityDirection);
}
void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag(WALL_TAG))
{
Debug.Log("Buton bir duvara çarptı ve durdu!");
rb.velocity = Vector2.zero;
}
}
}
mainmenu.cs
using UnityEngine;
using UnityEngine.SceneManagement;
public class MainMenu : MonoBehaviour
{
public void PlayGame()
{
Debug.Log("PlayGame() çağrıldı, sahne değiştiriliyor...");
SceneManager.LoadSceneAsync(1);
}
public void QuitGame()
{
Debug.Log("QuitGame() çağrıldı, oyun kapatılıyor...");
Application.Quit();
}
}
< /code>
Я пытался сбросить гравитацию, потому что он статичен, но опять же, это не работает. Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/793 ... s-in-unity
Мобильная версия