Hi,
I am new to all the c# scripting and everything.
As the title says, I am trying to create a loot box.
What i want is to be able to touch the box, making it disappear, then when the timer go to 0
the box reappear and do the same stuff each time I touch it.
this is my script :
public class lootBoxScript : MonoBehaviour
{
public float timer = 5f; // timer
GameObject lootbox;
public MeshRenderer MR; // for getting the gameobject MeshRendrer
public BoxCollider BC; // for getting the gameobject BoxCollider
public bool isTouch = false; // when the box is touchable
public bool isRepeat = false; // to be able to let the box "Re-do" the disappering
private void OnCollisionEnter(Collision collision)
{
// when the player touch the box, the box looses it Meshrender & Collider
if (collision.collider.tag == "Player")
{
MR.enabled = false;
BC.enabled = false;
isTouch = true;
}
}
private void Update()
{
if(isTouch)
{
timer -= Time.deltaTime;
if(timer <= 0)
{
isRepeat= true;
}
}
if(isRepeat.Equals(true))
{
MR.enabled = true;
BC.enabled = true;
isTouch = false;
timer = 5f;
}
}
with that code : the box disappear, timer go to 0, the box reappear BUT if i touch it again it do not diseappear.
can someone help me?
Kind regards