Если я деактивирую коллайдер 2D-плеера, а затем снова активирую его, игрок не сможет активировать другой объект? В инспекторе коллайдер снова активируется, но триггер по-прежнему не работает. Вот полный код:
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class CollectBubble : MonoBehaviour
{
//Public Variables
public TextMeshProUGUI infoText;
public GameObject Player, Coin;
//Private Variables
SpriteRenderer sprite;
CapsuleCollider2D capsuleCollider;
float timeLeft = 20.0f;
bool counter = false;
string info;
string info2;
int gadget;
// Start is called before the first frame update
void Start()
{
sprite = GetComponent<SpriteRenderer>();
capsuleCollider = GetComponent<CapsuleCollider2D>();
}
// Update is called once per frame
void Update()
{
if(counter == true)
{
timeLeft -= Time.deltaTime;
infoText.text = info + Mathf.Round(timeLeft) + " second/s " + info2;
if (timeLeft < 0)
{
if(gadget == 1)
{
capsuleCollider.enabled = true;
sprite.color = new Color(255, 255, 255, 1);
infoText.text = "";
gadget = 0;
counter = false;
}else if(gadget == 2)
{
CollectCoin.ccCounter = 1;
CollectCoin.ccCounter = 1;
infoText.text = "";
counter = false;
}else if(gadget == 3)
{
Player.transform.localScale = new Vector3((float)2.3, (float)2.3, 0);
infoText.text = "";
gadget = 0;
counter = false;
}
else if(gadget == 4)
{
Player.transform.localScale = new Vector3((float)2.3, (float)2.3, 0);
infoText.text = "";
gadget = 0;
counter = false;
}
else
{
return;
}
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if(collision.tag == "bubble")
{
GameObject.FindWithTag("bubble").transform.position = new Vector3(0, 0, -100);
int Gadget = Random.Range(1, 4);
if(Gadget == 1)
{
Invisibility();
}else if(Gadget == 2)
{
DoubleCoins();
}else if(Gadget == 3)
{
PlusCharacter();
}else if(Gadget == 4)
{
MinusCharacter();
}
}
}
private void Invisibility()
{
info = "Now you're for ";
info2 = " invisible!";
gadget = 1;
counter = true;
capsuleCollider.enabled = false;
sprite.color = new Color(255, 255, 255, (float)0.5);
}
private void DoubleCoins()
{
info = "Now you get double Coins for ";
info2 = "";
gadget = 2;
counter = true;
CollectCoin.ccCounter = 2;
CollectCoin.ccCounter = 2;
}
private void PlusCharacter()
{
info = "Now you're for ";
info2 = " twice as big as now!";
gadget = 3;
counter = true;
Player.transform.localScale = new Vector3((float)3.3, (float)3.3, 0);
}
private void MinusCharacter()
{
info = "Now you're for ";
info2 = " twice as small as now!";
gadget = 4;
counter = true;
Player.transform.localScale = new Vector3((float)1.3, (float)1.3, 0);
}
}
Объект, который я хочу активировать, является триггером, я не могу найти проблему. Спасибо за помощь!